lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Fri, 7 Aug 2020 10:02:48 +0800
From:   "luobin (L)" <luobin9@...wei.com>
To:     David Miller <davem@...emloft.net>
CC:     <linux-kernel@...r.kernel.org>, <netdev@...r.kernel.org>,
        <luoxianjun@...wei.com>, <yin.yinshi@...wei.com>,
        <cloud.wangxiaoyun@...wei.com>, <chiqijun@...wei.com>
Subject: Re: [PATCH net-next] hinic: fix strncpy output truncated compile
 warnings

On 2020/8/7 8:57, luobin (L) wrote:
> On 2020/8/7 3:01, David Miller wrote:
>> From: Luo bin <luobin9@...wei.com>
>> Date: Thu, 6 Aug 2020 15:48:30 +0800
>>
>>> diff --git a/drivers/net/ethernet/huawei/hinic/hinic_devlink.c b/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
>>> index c6adc776f3c8..1dc948c07b94 100644
>>> --- a/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
>>> +++ b/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
>>> @@ -342,9 +342,9 @@ static int chip_fault_show(struct devlink_fmsg *fmsg,
>>>  
>>>  	level = event->event.chip.err_level;
>>>  	if (level < FAULT_LEVEL_MAX)
>>> -		strncpy(level_str, fault_level[level], strlen(fault_level[level]));
>>> +		strncpy(level_str, fault_level[level], strlen(fault_level[level]) + 1);
>>>  	else
>>> -		strncpy(level_str, "Unknown", strlen("Unknown"));
>>> +		strncpy(level_str, "Unknown", sizeof(level_str));
>>>  
>>>  	if (level == FAULT_LEVEL_SERIOUS_FLR) {
>>
>> Please fix these cases consistently, either use the strlen()+1 pattern
>> or the "sizeof(destination)" one.
>>
>> Probably sizeof(destination) is best.
>> .
>>
> Will fix. Thanks. Level_str array is initialized to zero, so can't use the strlen()+1 pattern, I'll
> use strlen()+1 consistently.
> 
I have tried to use 'sizeof(level_str)' instead of 'strlen(fault_level[level]) + 1', but this will lead
to following compile warning:

In function ‘strncpy’,
    inlined from ‘chip_fault_show’ at drivers/net/ethernet/huawei/hinic/hinic_devlink.c:345:3:
./include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 17 equals destination size [-Wstringop-truncation]
  297 | #define __underlying_strncpy __builtin_strncpy

So I will use the strlen()+1 pattern consistently.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ