[libvirt] [PATCH 1/3] qemu: only parse basename when determining emulator properties

Eric Blake eblake at redhat.com
Wed Aug 28 04:00:28 UTC 2013


'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 at redhat.com>
---
 src/conf/domain_conf.c  |  6 ++++++
 src/qemu/qemu_command.c | 22 ++++++++++------------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8a187a6..d356181 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2704,6 +2704,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",
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index b5ac15a..bc55859 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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"
@@ -10764,29 +10765,25 @@ virDomainDefPtr 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;
@@ -10795,6 +10792,7 @@ virDomainDefPtr 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) {                                                        \
-- 
1.8.3.1




More information about the libvir-list mailing list