[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20140915.130721.589682835868904320.davem@davemloft.net>
Date: Mon, 15 Sep 2014 13:07:21 -0400 (EDT)
From: David Miller <davem@...emloft.net>
To: stephen@...workplumber.org
Cc: rickard_strandqvist@...ctrumdigital.se, mlindner@...vell.com,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] net: ethernet: marvell: sky2.c: Cleaning up missing
null-terminate in conjunction with strncpy
From: Stephen Hemminger <stephen@...workplumber.org>
Date: Sun, 14 Sep 2014 19:05:57 -0700
> On Sun, 14 Sep 2014 19:33:43 +0200
> Rickard Strandqvist <rickard_strandqvist@...ctrumdigital.se> wrote:
>
>> Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
>>
>> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@...ctrumdigital.se>
>> ---
>> drivers/net/ethernet/marvell/sky2.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
>> index dba48a5c..7053d38 100644
>> --- a/drivers/net/ethernet/marvell/sky2.c
>> +++ b/drivers/net/ethernet/marvell/sky2.c
>> @@ -4907,7 +4907,7 @@ static const char *sky2_name(u8 chipid, char *buf, int sz)
>> };
>>
>> if (chipid >= CHIP_ID_YUKON_XL && chipid <= CHIP_ID_YUKON_OP_2)
>> - strncpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz);
>> + strlcpy(buf, name[chipid - CHIP_ID_YUKON_XL], sz);
>> else
>> snprintf(buf, sz, "(chip %#x)", chipid);
>> return buf;
>
> Useless and unnecessary since the list of names is right there.
> Why not avoid the copy all together?
>
> Subject: sky2: avoid strncpy
>
> Don't use strncpy() since security thought police think it is bad.
>
> Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
I think providing the buffer on the stack of the thread executing the
probe is superior because it will allow enabling parallel probing
in the future.
I don't think you have to change that aspect to achieve your goal
of returning the const char * string when possible.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists