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.shevche...@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

Reply via email to