From: Andrew Lunn Date: Sat, 31 Oct 2020 18:17:00 +0000 (+0100) Subject: net: driver: hamradio: Fix potential unterminated string X-Git-Tag: v5.11-rc1~169^2~393 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e03d8a377fcc94f7c92fbd9dcdefe7d998a053e6;p=tomoyo%2Ftomoyo-test1.git net: driver: hamradio: Fix potential unterminated string With W=1 the following error is reported: In function ‘strncpy’, inlined from ‘hdlcdrv_ioctl’ at drivers/net/hamradio/hdlcdrv.c:600:4: ./include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 32 equals destination size [-Wstringop-truncation] 297 | #define __underlying_strncpy __builtin_strncpy | ^ ./include/linux/string.h:307:9: note: in expansion of macro ‘__underlying_strncpy’ 307 | return __underlying_strncpy(p, q, size); Replace strncpy with strlcpy to guarantee the string is terminated. Signed-off-by: Andrew Lunn Link: https://lore.kernel.org/r/20201031181700.1081693-1-andrew@lunn.ch Signed-off-by: Jakub Kicinski --- diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c index e7413a643929..9e0058154ac3 100644 --- a/drivers/net/hamradio/hdlcdrv.c +++ b/drivers/net/hamradio/hdlcdrv.c @@ -597,7 +597,7 @@ static int hdlcdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) case HDLCDRVCTL_DRIVERNAME: if (s->ops && s->ops->drvname) { - strncpy(bi.data.drivername, s->ops->drvname, + strlcpy(bi.data.drivername, s->ops->drvname, sizeof(bi.data.drivername)); break; }