[PATCH] Fix MAC address parsing for 1-digit case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



libvirt fails in parsing when MAC address like "00:16:3e:12:3:61"
is specified for installation.
This is because virt-install can pass 1-digit (like 3) for
MAC address from Cset:316 for Solaris
But libvirt cannot support this MAC 1-digit (like 3) parameter.

This patch fixes libvirt parsing in the MAC address
against virt-inst Cset:316

Thanks

Signed-off-by: Hiroyuki Kaguchi <fj7025cf@xxxxxxxxxxxxxxxxx>
? parse_macaddr.patch
Index: src/xml.c
===================================================================
RCS file: /data/cvs/libvirt/src/xml.c,v
retrieving revision 1.113
diff -u -r1.113 xml.c
--- src/xml.c	27 Feb 2008 04:35:08 -0000	1.113
+++ src/xml.c	18 Mar 2008 05:30:14 -0000
@@ -17,6 +17,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <limits.h>
+#include <ctype.h>
 #ifdef WITH_XEN
 #include <xs.h>
 #endif
@@ -537,6 +538,44 @@
  ************************************************************************/
 #if WITH_XEN
 /**
+ * parseMacAddr:
+ * @str: mac addrress string
+ * @addr: mac addrress numbers
+ *
+ * Parse a mac addrress
+ *
+ * Returns 0 in case success or -1 in case of error.
+ */
+static int
+parseMacAddr(const char* str, unsigned char *addr)
+{
+    int i;
+    for (i = 0; i < 6; i++) {
+        char *end_ptr;
+        unsigned long result;
+
+        if (!isdigit(*str) && !isalpha(*str))
+            break;
+
+        result = strtoul(str, &end_ptr, 16);
+
+        if ((end_ptr - str) < 1 || 2 < (end_ptr - str) ||
+            (errno == ERANGE) ||
+            (0xFF < result))
+            break;
+
+        addr[i] = (unsigned char) result;
+
+        if (*end_ptr != ':')
+            return (i == 5) ? 0 : -1;
+
+        str = end_ptr + 1;
+    }
+
+    return -1;
+}
+
+/**
  * virtDomainParseXMLGraphicsDescImage:
  * @conn: pointer to the hypervisor connection
  * @node: node containing graphics description
@@ -1233,22 +1272,8 @@
 
     virBufferAddLit(buf, "(vif ");
     if (mac != NULL) {
-        unsigned int addr[12];
-        int tmp = sscanf((const char *) mac,
-		     "%01x%01x:%01x%01x:%01x%01x:%01x%01x:%01x%01x:%01x%01x",
-                         (unsigned int *) &addr[0],
-                         (unsigned int *) &addr[1],
-                         (unsigned int *) &addr[2],
-                         (unsigned int *) &addr[3],
-                         (unsigned int *) &addr[4],
-                         (unsigned int *) &addr[5],
-                         (unsigned int *) &addr[6],
-                         (unsigned int *) &addr[7],
-                         (unsigned int *) &addr[8],
-                         (unsigned int *) &addr[9],
-                         (unsigned int *) &addr[10],
-                         (unsigned int *) &addr[11]);
-        if (tmp != 12 || strlen((const char *) mac) != 17) {
+        unsigned char addr[6];
+        if (parseMacAddr((const char*) mac, addr) == -1) {
             virXMLError(conn, VIR_ERR_INVALID_MAC, (const char *) mac, 0);
             goto error;
         }
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]