]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: only parse basename when determining emulator properties
authorEric Blake <eblake@redhat.com>
Mon, 26 Aug 2013 22:04:19 +0000 (16:04 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 6 Sep 2013 15:21:02 +0000 (09:21 -0600)
'virsh domxml-from-native' and 'virsh qemu-attach' could misbehave
for an emulator installed in (a somewhat unlikely) location
such as /usr/local/qemu-1.6/qemu-system-x86_64 or (an even less
likely) /opt/notxen/qemu-system-x86_64.  Limit the strstr seach
to just the basename of the file where we are assuming details
about the binary based on its name.

While testing, I accidentally triggered a core dump during strcmp
when I forgot to set os.type on one of my code paths; this patch
changes such a coding error to raise a nicer internal error instead.

* src/qemu/qemu_command.c (qemuParseCommandLine): Compute basename
earlier.
* src/conf/domain_conf.c (virDomainDefPostParseInternal): Avoid
NULL deref.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/conf/domain_conf.c
src/qemu/qemu_command.c

index 216bf7a7613bdb954c94a216224d8d34d429a27c..aed2a9dbccabc2c558f065f388fc308ad24738b0 100644 (file)
@@ -2709,6 +2709,12 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
 {
     size_t i;
 
+    if (!def->os.type) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("hypervisor type must be specified"));
+        return -1;
+    }
+
     /* verify init path for container based domains */
     if (STREQ(def->os.type, "exe") && !def->os.init) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
index 91ca86a3c3d8220fcc5644d0d8b72cdec70b39ba..4e8ef01b613d9b33c1b9bb0681f61d5bbd94f04f 100644 (file)
@@ -28,6 +28,7 @@
 #include "qemu_capabilities.h"
 #include "qemu_bridge_filter.h"
 #include "cpu/cpu.h"
+#include "dirname.h"
 #include "passfd.h"
 #include "viralloc.h"
 #include "virlog.h"
@@ -10945,29 +10946,25 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
     if (VIR_STRDUP(def->emulator, progargv[0]) < 0)
         goto error;
 
-    if (strstr(def->emulator, "kvm")) {
-        def->virtType = VIR_DOMAIN_VIRT_KVM;
-        def->features |= (1 << VIR_DOMAIN_FEATURE_PAE);
-    }
-
+    if (!(path = last_component(def->emulator)))
+        goto error;
 
-    if (strstr(def->emulator, "xenner")) {
+    if (strstr(path, "xenner")) {
         def->virtType = VIR_DOMAIN_VIRT_KVM;
         if (VIR_STRDUP(def->os.type, "xen") < 0)
             goto error;
     } else {
         if (VIR_STRDUP(def->os.type, "hvm") < 0)
             goto error;
+        if (strstr(path, "kvm")) {
+            def->virtType = VIR_DOMAIN_VIRT_KVM;
+            def->features |= (1 << VIR_DOMAIN_FEATURE_PAE);
+        }
     }
 
-    if (STRPREFIX(def->emulator, "qemu"))
-        path = def->emulator;
-    else
-        path = strstr(def->emulator, "qemu");
     if (def->virtType == VIR_DOMAIN_VIRT_KVM)
         def->os.arch = qemuCaps->host.arch;
-    else if (path &&
-             STRPREFIX(path, "qemu-system-"))
+    else if (STRPREFIX(path, "qemu-system-"))
         def->os.arch = virArchFromString(path + strlen("qemu-system-"));
     else
         def->os.arch = VIR_ARCH_I686;
@@ -10976,6 +10973,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
         (def->os.arch == VIR_ARCH_X86_64))
         def->features |= (1 << VIR_DOMAIN_FEATURE_ACPI)
         /*| (1 << VIR_DOMAIN_FEATURE_APIC)*/;
+
 #define WANT_VALUE()                                                   \
     const char *val = progargv[++i];                                   \
     if (!val) {                                                        \