Index: src/xm_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xm_internal.c,v
retrieving revision 1.41
diff -u -p -r1.41 xm_internal.c
--- src/xm_internal.c	10 Oct 2007 17:55:38 -0000	1.41
+++ src/xm_internal.c	23 Oct 2007 04:55:26 -0000
@@ -1528,13 +1528,6 @@ static int xenXMParseXMLDisk(xmlNodePtr 
         cur = cur->next;
     }
 
-    if (source == NULL) {
-        if (target != NULL)
-            xmlFree(target);
-        if (device != NULL)
-            xmlFree(device);
-        return (-1);
-    }
     if (target == NULL) {
         if (source != NULL)
             xmlFree(source);
@@ -1565,6 +1558,14 @@ static int xenXMParseXMLDisk(xmlNodePtr 
         }
     }
 
+    if (source == NULL && !cdrom) {
+        if (target != NULL)
+            xmlFree(target);
+        if (device != NULL)
+            xmlFree(device);
+        return (-1);
+    }
+
     if (drvName) {
         buflen += strlen((const char*)drvName) + 1;
         if (!strcmp((const char*)drvName, "tap")) {
@@ -1580,7 +1581,10 @@ static int xenXMParseXMLDisk(xmlNodePtr 
             buflen += 4;
     }
 
-    buflen += strlen((const char*)source) + 1;
+    if(source)
+        buflen += strlen((const char*)source) + 1;
+    else
+        buflen += 1;
     buflen += strlen((const char*)target) + 1;
     if (hvm && xendConfigVersion == 1) /* ioemu: */
         buflen += 6;
@@ -1593,23 +1597,27 @@ static int xenXMParseXMLDisk(xmlNodePtr 
     if (!(buf = malloc(buflen)))
         goto cleanup;
 
-    if (drvName) {
-        strcpy(buf, (const char*)drvName);
-        if (!strcmp((const char*)drvName, "tap")) {
-            strcat(buf, ":");
-            if (drvType)
-                strcat(buf, (const char*)drvType);
+    if(source) {
+        if (drvName) {
+            strcpy(buf, (const char*)drvName);
+            if (!strcmp((const char*)drvName, "tap")) {
+                strcat(buf, ":");
+                if (drvType)
+                    strcat(buf, (const char*)drvType);
+                else
+                    strcat(buf, "aio");
+            }
+        } else {
+            if (typ == 0)
+                strcpy(buf, "file");
             else
-                strcat(buf, "aio");
+                strcpy(buf, "phy");
         }
+        strcat(buf, ":");
+        strcat(buf, (const char*)source);
     } else {
-        if (typ == 0)
-            strcpy(buf, "file");
-        else
-            strcpy(buf, "phy");
+        strcpy(buf, "");
     }
-    strcat(buf, ":");
-    strcat(buf, (const char*)source);
     strcat(buf, ",");
     if (hvm && xendConfigVersion == 1)
         strcat(buf, "ioemu:");
@@ -1629,7 +1637,8 @@ static int xenXMParseXMLDisk(xmlNodePtr 
     xmlFree(drvName);
     xmlFree(device);
     xmlFree(target);
-    xmlFree(source);
+    if(source)
+        xmlFree(source);
     *disk = buf;
 
     return (ret);
