]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: rely on ether_addr_from_string instead of sscanf 3235/head
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Tue, 17 May 2016 20:43:36 +0000 (16:43 -0400)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Tue, 17 May 2016 20:55:20 +0000 (16:55 -0400)
src/libsystemd-network/network-internal.c

index 2badcdff58498d51a6d745ad679f813c1518637d..046b0f939347df901293ab2a1ba415260eaea4af 100644 (file)
@@ -27,6 +27,7 @@
 #include "condition.h"
 #include "conf-parser.h"
 #include "dhcp-lease-internal.h"
+#include "ether-addr-util.c"
 #include "hexdecoct.h"
 #include "log.h"
 #include "network-internal.h"
@@ -272,6 +273,8 @@ int config_parse_hwaddr(const char *unit,
                         void *userdata) {
         struct ether_addr **hwaddr = data;
         struct ether_addr *n;
+        const char *start;
+        size_t offset;
         int r;
 
         assert(filename);
@@ -283,14 +286,10 @@ int config_parse_hwaddr(const char *unit,
         if (!n)
                 return log_oom();
 
-        r = sscanf(rvalue, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
-                   &n->ether_addr_octet[0],
-                   &n->ether_addr_octet[1],
-                   &n->ether_addr_octet[2],
-                   &n->ether_addr_octet[3],
-                   &n->ether_addr_octet[4],
-                   &n->ether_addr_octet[5]);
-        if (r != 6) {
+        start = rvalue + strspn(rvalue, WHITESPACE);
+        r = ether_addr_from_string(start, n, &offset);
+
+        if (r || (start[offset + strspn(start + offset, WHITESPACE)] != '\0')) {
                 log_syntax(unit, LOG_ERR, filename, line, 0, "Not a valid MAC address, ignoring assignment: %s", rvalue);
                 free(n);
                 return 0;