]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix crash using bogus arch in QEMU
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 30 Jan 2009 17:12:28 +0000 (17:12 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 30 Jan 2009 17:12:28 +0000 (17:12 +0000)
ChangeLog
src/capabilities.c
src/capabilities.h
src/domain_conf.c
src/qemu_conf.c

index c332e201d3b63f1db55dfb7848dfdd4d42bc8a5c..d075e5617050cd543c775d874fc1f88017ba15d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Fri Jan 30 16:12:22 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
+
+       Fix crash when using bogus arch type
+       * src/capabilities.c, src/capabilities.h: Add method to query
+       for supported arch+ostype combo
+       * src/domain_conf.c: Validate requested arch+ostype against
+       supported capabilities
+       * src/qemu_conf.c: Sanity check to avoid deferencing NULL
+       machine type
+
 Fri Jan 30 16:58:22 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
 
        Misc QEMU driver startup fixes
index 158873ced944b556eadd3c3003e3484d29ad5e94..3a2333207d08d9c912355f49c3099a53b043e502 100644 (file)
@@ -432,6 +432,30 @@ virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
 }
 
 
+/**
+ * virCapabilitiesSupportsGuestOSType:
+ * @caps: capabilities to query
+ * @ostype: OS type to search for (eg 'hvm', 'xen')
+ * @arch: Architecture to search for (eg, 'i686', 'x86_64')
+ *
+ * Returns non-zero if the capabilities support the
+ * requested operating system type
+ */
+extern int
+virCapabilitiesSupportsGuestArch(virCapsPtr caps,
+                                 const char *ostype,
+                                 const char *arch)
+{
+    int i;
+    for (i = 0 ; i < caps->nguests ; i++) {
+        if (STREQ(caps->guests[i]->ostype, ostype) &&
+            STREQ(caps->guests[i]->arch.name, arch))
+            return 1;
+    }
+    return 0;
+}
+
+
 /**
  * virCapabilitiesDefaultGuestArch:
  * @caps: capabilities to query
index c991ea192d3f81770875b6f1fbbfb92e5d63da18..be3296c1ef28ef018680b5d5752fbce5dfbc3b05 100644 (file)
@@ -162,6 +162,12 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest,
 extern int
 virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
                                    const char *ostype);
+extern int
+virCapabilitiesSupportsGuestArch(virCapsPtr caps,
+                                 const char *ostype,
+                                 const char *arch);
+
+
 extern const char *
 virCapabilitiesDefaultGuestArch(virCapsPtr caps,
                                 const char *ostype);
index adcd032221abb83c0a7591080ce2f260c4582e22..1bf46f1f7e15c0c2ee7671689e080ac64e8de986 100644 (file)
@@ -2038,7 +2038,14 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
     }
 
     def->os.arch = virXPathString(conn, "string(./os/type[1]/@arch)", ctxt);
-    if (!def->os.arch) {
+    if (def->os.arch) {
+        if (!virCapabilitiesSupportsGuestArch(caps, def->os.type, def->os.arch)) {
+            virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+                                 _("os type '%s' & arch '%s' combination is not supported"),
+                                 def->os.type, def->os.arch);
+            goto error;
+        }
+    } else {
         const char *defaultArch = virCapabilitiesDefaultGuestArch(caps, def->os.type);
         if (defaultArch == NULL) {
             virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
index 890434f2da1168a4b75288cd63959e6bd33e3ec1..b2d888341bf593c6a9c41b3139abe1fef1231fa4 100644 (file)
@@ -837,8 +837,16 @@ int qemudBuildCommandLine(virConnectPtr conn,
 
     ADD_ARG_LIT(emulator);
     ADD_ARG_LIT("-S");
-    ADD_ARG_LIT("-M");
-    ADD_ARG_LIT(vm->def->os.machine);
+
+    /* This should *never* be NULL, since we always provide
+     * a machine in the capabilities data for QEMU. So this
+     * check is just here as a safety in case the unexpected
+     * happens */
+    if (vm->def->os.machine) {
+        ADD_ARG_LIT("-M");
+        ADD_ARG_LIT(vm->def->os.machine);
+    }
+
     if (disableKQEMU)
         ADD_ARG_LIT("-no-kqemu");
     ADD_ARG_LIT("-m");