Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20201031181700.1081693-1-andrew@lunn.ch
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Andrew Lunn and committed by
Jakub Kicinski
e03d8a37 a344a1e8

+1 -1
+1 -1
drivers/net/hamradio/hdlcdrv.c
··· 597 597 598 598 case HDLCDRVCTL_DRIVERNAME: 599 599 if (s->ops && s->ops->drvname) { 600 - strncpy(bi.data.drivername, s->ops->drvname, 600 + strlcpy(bi.data.drivername, s->ops->drvname, 601 601 sizeof(bi.data.drivername)); 602 602 break; 603 603 }