netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/4] lib/net_utils: Relax NULL-termination requirement on input string
@ 2017-12-19 19:14 Andy Shevchenko
  2017-12-19 19:14 ` [PATCH v1 2/4] lib/net_utils: Introduce mac_pton_from_user() Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andy Shevchenko @ 2017-12-19 19:14 UTC (permalink / raw)
  To: David S. Miller, netdev, Larry Finger, Florian Schilhabel, devel,
	Greg Kroah-Hartman
  Cc: Andy Shevchenko

We have not been caring about garbage at the end of input string and this
change doesn't affect it. What we prevent here is possibility to go over
boundaries when input string is not NULL terminated at all.

Allow mac_pton() work on non-NULL terminated strings.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/net_utils.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/net_utils.c b/lib/net_utils.c
index af525353395d..d32c6961fe0f 100644
--- a/lib/net_utils.c
+++ b/lib/net_utils.c
@@ -4,12 +4,14 @@
 #include <linux/ctype.h>
 #include <linux/kernel.h>
 
+#define MAC_PTON_MINLEN		(3 * ETH_ALEN - 1)
+
 bool mac_pton(const char *s, u8 *mac)
 {
 	int i;
 
 	/* XX:XX:XX:XX:XX:XX */
-	if (strlen(s) < 3 * ETH_ALEN - 1)
+	if (strnlen(s, MAC_PTON_MINLEN) < MAC_PTON_MINLEN)
 		return false;
 
 	/* Don't dirty result unless string is valid MAC. */
-- 
2.15.1

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

end of thread, other threads:[~2017-12-20 15:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-19 19:14 [PATCH v1 1/4] lib/net_utils: Relax NULL-termination requirement on input string Andy Shevchenko
2017-12-19 19:14 ` [PATCH v1 2/4] lib/net_utils: Introduce mac_pton_from_user() Andy Shevchenko
2017-12-20  7:13   ` Greg Kroah-Hartman
2017-12-20 15:51     ` David Miller
2017-12-19 19:14 ` [PATCH v1 3/4] staging: rtl8723bs: Replace mac address parsing Andy Shevchenko
2017-12-19 19:14 ` [PATCH v1 4/4] staging: rtl8712: " Andy Shevchenko

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).