[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171219191412.14880-1-andriy.shevchenko@linux.intel.com>
Date: Tue, 19 Dec 2017 21:14:09 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: "David S. Miller" <davem@...emloft.net>, netdev@...r.kernel.org,
Larry Finger <Larry.Finger@...inger.net>,
Florian Schilhabel <florian.c.schilhabel@...glemail.com>,
devel@...verdev.osuosl.org,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: [PATCH v1 1/4] lib/net_utils: Relax NULL-termination requirement on input string
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@...ux.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
Powered by blists - more mailing lists