[patch 4/9] Misc. fixes for the qemud network iface code

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

 



Some misc fixes for the qemud network interface code:

 - don't try and free a NULL macaddr - xmlFree(), unlike all the
   rest of the xml*Free() functions, isn't NULL safe
 - handle an unspecifed MAC address (that is allowed, right?)
 - fix the argv freeing code in qemudBuildCommandLine()
 - fix copy and paste error in qemudGenerateXML()

Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx>

Index: libvirt-foo/qemud/conf.c
===================================================================
--- libvirt-foo.orig/qemud/conf.c	2007-02-14 14:41:37.000000000 +0000
+++ libvirt-foo.orig/qemud/conf.c	2007-02-14 14:41:37.000000000 +0000
@@ -856,10 +856,16 @@ int qemudBuildCommandLine(struct qemud_s
     } else {
         while (net) {
             char nic[3+1+7+1+17+1];
-            sprintf(nic, "nic,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
-                    net->mac[0], net->mac[1],
-                    net->mac[2], net->mac[3],
-                    net->mac[4], net->mac[5]);
+
+            if (!net->mac[0] && !net->mac[1] && !net->mac[2] &&
+                !net->mac[3] && !net->mac[4] && !net->mac[5]) {
+                strncpy(nic, "nic", 4);
+            } else {
+                sprintf(nic, "nic,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
+                        net->mac[0], net->mac[1],
+                        net->mac[2], net->mac[3],
+                        net->mac[4], net->mac[5]);
+            }
 
             if (!((*argv)[++n] = strdup("-net")))
                 goto no_memory;
@@ -896,8 +902,8 @@ int qemudBuildCommandLine(struct qemud_s
  no_memory:
     if (argv) {
         for (i = 0 ; i < n ; i++)
-            free(argv[i]);
-        free(argv);
+            free((*argv)[i]);
+        free(*argv);
     }
     qemudReportError(server, VIR_ERR_NO_MEMORY, "argv");
     return -1;
@@ -1353,8 +1359,7 @@ char *qemudGenerateXML(struct qemud_serv
     }
 
     net = vm->def.nets;
-    disk = vm->def.disks;
-    while (disk) {
+    while (net) {
         const char *types[] = {
             "user",
             "tap",
@@ -1367,7 +1372,9 @@ char *qemudGenerateXML(struct qemud_serv
                               types[net->type]) < 0)
             goto no_memory;
 
-        if (qemudBufferPrintf(&buf, "      <mac address='%02x:%02x:%02x:%02x:%02x:%02x'/>\n",
+        if (net->mac[0] && net->mac[1] && net->mac[2] &&
+            net->mac[3] && net->mac[4] && net->mac[5] &&
+            qemudBufferPrintf(&buf, "      <mac address='%02x:%02x:%02x:%02x:%02x:%02x'/>\n",
                               net->mac[0], net->mac[1], net->mac[2],
                               net->mac[3], net->mac[4], net->mac[5]) < 0)
             goto no_memory;
@@ -1375,7 +1382,7 @@ char *qemudGenerateXML(struct qemud_serv
         if (qemudBufferPrintf(&buf, "    </interface>\n") < 0)
             goto no_memory;
 
-        disk = disk->next;
+        net = net->next;
     }
 
     if (vm->def.graphicsType == QEMUD_GRAPHICS_VNC) {

-- 


[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]