lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20231002233946.16703-3-mcpratt@protonmail.com>
Date:   Mon, 02 Oct 2023 23:40:07 +0000
From:   Michael Pratt <mcpratt@...tonmail.com>
To:     netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Cc:     "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Paolo Abeni <pabeni@...hat.com>,
        Rafal Milecki <zajec5@...il.com>,
        Christian Marangi <ansuelsmth@...il.com>,
        Michael Pratt <mcpratt@...me>
Subject: [PATCH 2/2] mac_pton: support MAC addresses without delimiters

From: Michael Pratt <mcpratt@...me>

Some network hardware vendors may do something unique
when storing the MAC address into hardware in ASCII,
like leaving out delimiters in order to avoid
using more than a single 16-byte logical addressing line.

Allow parsing of MAC addresses without a delimiter.

Signed-off-by: Michael Pratt <mcpratt@...me>
---
 lib/net_utils.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/net_utils.c b/lib/net_utils.c
index ecb7625e1dec..f5fd1926af59 100644
--- a/lib/net_utils.c
+++ b/lib/net_utils.c
@@ -7,9 +7,14 @@
 
 bool mac_pton(const char *s, u8 *mac)
 {
+	size_t minlen = 2 * ETH_ALEN;
 	size_t maxlen = 3 * ETH_ALEN - 1;
 	int i;
 
+	/* AABBCCDDEEFF */
+	if (strnlen(s, maxlen) == minlen)
+		goto no_delim;
+
 	/* XX:XX:XX:XX:XX:XX */
 	if (strnlen(s, maxlen) < maxlen)
 		return false;
@@ -25,5 +30,15 @@ bool mac_pton(const char *s, u8 *mac)
 		mac[i] = (hex_to_bin(s[i * 3]) << 4) | hex_to_bin(s[i * 3 + 1]);
 	}
 	return true;
+
+no_delim:
+	for (i = 0; i < minlen; i++) {
+		if (!isxdigit(s[i]))
+			return false;
+	}
+	for (i = 0; i < ETH_ALEN; i++) {
+		mac[i] = (hex_to_bin(s[i * 2]) << 4) | hex_to_bin(s[i * 2 + 1]);
+	}
+	return true;
 }
 EXPORT_SYMBOL(mac_pton);
-- 
2.30.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ