diff mbox series

[net-next] net: driver: hamradio: Fix potential unterminated string

Message ID 20201031181700.1081693-1-andrew@lunn.ch
State Accepted
Delegated to: David Miller
Headers show
Series [net-next] net: driver: hamradio: Fix potential unterminated string | expand

Checks

Context Check Description
jkicinski/cover_letter success Link
jkicinski/fixes_present success Link
jkicinski/patch_count success Link
jkicinski/tree_selection success Clearly marked for net-next
jkicinski/subject_prefix success Link
jkicinski/source_inline success Was 0 now: 0
jkicinski/verify_signedoff success Link
jkicinski/module_param success Was 0 now: 0
jkicinski/build_32bit success Errors and warnings before: 1 this patch: 0
jkicinski/kdoc success Errors and warnings before: 0 this patch: 0
jkicinski/verify_fixes success Link
jkicinski/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
jkicinski/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
jkicinski/header_inline success Link
jkicinski/stable success Stable not CCed

Commit Message

Andrew Lunn Oct. 31, 2020, 6:17 p.m. UTC
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>
---
 drivers/net/hamradio/hdlcdrv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jakub Kicinski Nov. 3, 2020, 12:11 a.m. UTC | #1
On Sat, 31 Oct 2020 19:17:00 +0100 Andrew Lunn wrote:
> 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>

Looks like the longest name in tree is 14, so there should be no
truncation and therefore uAPI change.

Applied, thanks!
diff mbox series

Patch

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;
 		}