prism54: call BUG_ON() earlier
Subsystems (2)
PATCH 1/1 prism54: call BUG_ON() earlier
This test is off by one because strlen() doesn't include the NULL terminator.
drivers/net/wireless/prism54/isl_ioctl.c +1 -1
@@ -2067,7 +2067,7 @@ send_simple_event(islpci_private *priv, const char *str) memptr =kmalloc (IW_CUSTOM_MAX ,GFP_KERNEL );if (!memptr)return ; -BUG_ON (n >IW_CUSTOM_MAX ); +BUG_ON (n >=IW_CUSTOM_MAX ); wrqu.data.pointer = memptr; wrqu.data.length = n;strcpy (memptr, str);
Quoted 11 lines · Dan Carpenter
This test is off by one because
strlen()doesn't include the NULL terminator.Signed-off-by Dan Carpenter <[email protected]>drivers/net/wireless/prism54/isl_ioctl.c +0
-0
drivers/net/wireless/prism54/isl_ioctl.c send_simple_event(islpci_private *priv, const char *str) · line 2073
Quoted 8 lines
drivers/net/wireless/prism54/isl_ioctl.c +1
-1@@ -2067,7 +2067,7 @@ send_simple_event(islpci_private *priv, const char *str) memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL); if (!memptr) return; - BUG_ON(n > IW_CUSTOM_MAX); + BUG_ON(n >= IW_CUSTOM_MAX); wrqu.data.pointer = memptr; wrqu.data.length = n; strcpy(memptr, str);
send_simple_event() never passes a NULL terminated string though. What does this fix today? If nothing then better leave as-is.
Luis
Quoted 24 lines · Luis R. Rodriguez
Quoted 11 lines · Dan Carpenter
This test is off by one because
strlen()doesn't include the NULL terminator.Signed-off-by Dan Carpenter <[email protected]>drivers/net/wireless/prism54/isl_ioctl.c +0
-0drivers/net/wireless/prism54/isl_ioctl.c send_simple_event(islpci_private *priv, const char *str) · line 2073
Quoted 8 lines
drivers/net/wireless/prism54/isl_ioctl.c +1
-1@@ -2067,7 +2067,7 @@ send_simple_event(islpci_private *priv, const char *str) memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL); if (!memptr) return; - BUG_ON(n > IW_CUSTOM_MAX); + BUG_ON(n >= IW_CUSTOM_MAX); wrqu.data.pointer = memptr; wrqu.data.length = n; strcpy(memptr, str);
send_simple_event()never passes a NULL terminated string though. What does this fix today? If nothing then better leave as-is.
Quoted 1 line
Luis
It doesn't fix any bugs in the current code, but it's a necessary clean up.
memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL);
^^^^^^^^^^^^^
This is the size of memptr.
if (!memptr)
return;
BUG_ON(n > IW_CUSTOM_MAX);
^^^^^^^^^^^^^^^^^^^^^^^^^^
This is an off-by-one check.
wrqu.data.pointer = memptr;
wrqu.data.length = n;
strcpy(memptr, str);
^^^^^^^^^^^^^^^^^^^^
This would be a silent memory corruption.In the current code we only use short event strings so the check isn't needed. But we should either correct the check or remove it.
regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Of course the main reasons is that it silences a static checkers warning. :P
drivers/net/wireless/prism54/isl_ioctl.c +2073 send_simple_event(12)
error: strcpy() 'str' too large for 'memptr' (257 vs 256)
regards,
dan carpenter