netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] drivers: net: sky2: Fix -Wstringop-truncation with W=1
@ 2020-11-10  2:32 Andrew Lunn
  2020-11-10  6:06 ` Stephen Hemminger
  2020-11-12  4:24 ` Jakub Kicinski
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Lunn @ 2020-11-10  2:32 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: netdev, Mirko Lindner, Andrew Lunn, Stephen Hemminger

In function ‘strncpy’,
    inlined from ‘sky2_name’ at drivers/net/ethernet/marvell/sky2.c:4903:3,
    inlined from ‘sky2_probe’ at drivers/net/ethernet/marvell/sky2.c:5049:2:
./include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]

None of the device names are 16 characters long, so it was never an
issue. But replace the strncpy with an snprintf() to prevent the
theoretical overflow.

Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 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 25981a7a43b5..ebe1406c6e64 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -4900,7 +4900,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);
+		snprintf(buf, sz, "%s", name[chipid - CHIP_ID_YUKON_XL]);
 	else
 		snprintf(buf, sz, "(chip %#x)", chipid);
 	return buf;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] drivers: net: sky2: Fix -Wstringop-truncation with W=1
  2020-11-10  2:32 [PATCH net-next v2] drivers: net: sky2: Fix -Wstringop-truncation with W=1 Andrew Lunn
@ 2020-11-10  6:06 ` Stephen Hemminger
  2020-11-12  4:24 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2020-11-10  6:06 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: Jakub Kicinski, netdev, Mirko Lindner

On Tue, 10 Nov 2020 03:32:22 +0100
Andrew Lunn <andrew@lunn.ch> wrote:

> In function ‘strncpy’,
>     inlined from ‘sky2_name’ at drivers/net/ethernet/marvell/sky2.c:4903:3,
>     inlined from ‘sky2_probe’ at drivers/net/ethernet/marvell/sky2.c:5049:2:
> ./include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
> 
> None of the device names are 16 characters long, so it was never an
> issue. But replace the strncpy with an snprintf() to prevent the
> theoretical overflow.
> 
> Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Acked-by: Stephen Hemminger <stephen@networkplumber.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] drivers: net: sky2: Fix -Wstringop-truncation with W=1
  2020-11-10  2:32 [PATCH net-next v2] drivers: net: sky2: Fix -Wstringop-truncation with W=1 Andrew Lunn
  2020-11-10  6:06 ` Stephen Hemminger
@ 2020-11-12  4:24 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2020-11-12  4:24 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: netdev, Mirko Lindner, Stephen Hemminger

On Tue, 10 Nov 2020 03:32:22 +0100 Andrew Lunn wrote:
> In function ‘strncpy’,
>     inlined from ‘sky2_name’ at drivers/net/ethernet/marvell/sky2.c:4903:3,
>     inlined from ‘sky2_probe’ at drivers/net/ethernet/marvell/sky2.c:5049:2:
> ./include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 16 equals destination size [-Wstringop-truncation]
> 
> None of the device names are 16 characters long, so it was never an
> issue. But replace the strncpy with an snprintf() to prevent the
> theoretical overflow.
> 
> Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Applied, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-12  5:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10  2:32 [PATCH net-next v2] drivers: net: sky2: Fix -Wstringop-truncation with W=1 Andrew Lunn
2020-11-10  6:06 ` Stephen Hemminger
2020-11-12  4:24 ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).