render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
43fe83
From 0befde5c74a0d886f4683d1fb669641fbe053cc2 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <0befde5c74a0d886f4683d1fb669641fbe053cc2.1380112457.git.jdenemar@redhat.com>
43fe83
From: Eric Blake <eblake@redhat.com>
43fe83
Date: Mon, 23 Sep 2013 11:10:03 -0600
43fe83
Subject: [PATCH] qemu: only parse basename when determining emulator
43fe83
 properties
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=1010617
43fe83
43fe83
'virsh domxml-from-native' and 'virsh qemu-attach' could misbehave
43fe83
for an emulator installed in (a somewhat unlikely) location
43fe83
such as /usr/local/qemu-1.6/qemu-system-x86_64 or (an even less
43fe83
likely) /opt/notxen/qemu-system-x86_64.  Limit the strstr seach
43fe83
to just the basename of the file where we are assuming details
43fe83
about the binary based on its name.
43fe83
43fe83
While testing, I accidentally triggered a core dump during strcmp
43fe83
when I forgot to set os.type on one of my code paths; this patch
43fe83
changes such a coding error to raise a nicer internal error instead.
43fe83
43fe83
* src/qemu/qemu_command.c (qemuParseCommandLine): Compute basename
43fe83
earlier.
43fe83
* src/conf/domain_conf.c (virDomainDefPostParseInternal): Avoid
43fe83
NULL deref.
43fe83
43fe83
Signed-off-by: Eric Blake <eblake@redhat.com>
43fe83
(cherry picked from commit 6a373fb2c95300d632a7371c893a301364f8dcb5)
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/conf/domain_conf.c  |  6 ++++++
43fe83
 src/qemu/qemu_command.c | 22 ++++++++++------------
43fe83
 2 files changed, 16 insertions(+), 12 deletions(-)
43fe83
43fe83
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
43fe83
index 566940c..b46381f 100644
43fe83
--- a/src/conf/domain_conf.c
43fe83
+++ b/src/conf/domain_conf.c
43fe83
@@ -2704,6 +2704,12 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
43fe83
 {
43fe83
     size_t i;
43fe83
 
43fe83
+    if (!def->os.type) {
43fe83
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
43fe83
+                       _("hypervisor type must be specified"));
43fe83
+        return -1;
43fe83
+    }
43fe83
+
43fe83
     /* verify init path for container based domains */
43fe83
     if (STREQ(def->os.type, "exe") && !def->os.init) {
43fe83
         virReportError(VIR_ERR_XML_ERROR, "%s",
43fe83
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
43fe83
index 6a6b3cd..dd63e01 100644
43fe83
--- a/src/qemu/qemu_command.c
43fe83
+++ b/src/qemu/qemu_command.c
43fe83
@@ -28,6 +28,7 @@
43fe83
 #include "qemu_capabilities.h"
43fe83
 #include "qemu_bridge_filter.h"
43fe83
 #include "cpu/cpu.h"
43fe83
+#include "dirname.h"
43fe83
 #include "passfd.h"
43fe83
 #include "viralloc.h"
43fe83
 #include "virlog.h"
43fe83
@@ -10765,29 +10766,25 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
43fe83
     if (VIR_STRDUP(def->emulator, progargv[0]) < 0)
43fe83
         goto error;
43fe83
 
43fe83
-    if (strstr(def->emulator, "kvm")) {
43fe83
-        def->virtType = VIR_DOMAIN_VIRT_KVM;
43fe83
-        def->features |= (1 << VIR_DOMAIN_FEATURE_PAE);
43fe83
-    }
43fe83
-
43fe83
+    if (!(path = last_component(def->emulator)))
43fe83
+        goto error;
43fe83
 
43fe83
-    if (strstr(def->emulator, "xenner")) {
43fe83
+    if (strstr(path, "xenner")) {
43fe83
         def->virtType = VIR_DOMAIN_VIRT_KVM;
43fe83
         if (VIR_STRDUP(def->os.type, "xen") < 0)
43fe83
             goto error;
43fe83
     } else {
43fe83
         if (VIR_STRDUP(def->os.type, "hvm") < 0)
43fe83
             goto error;
43fe83
+        if (strstr(path, "kvm")) {
43fe83
+            def->virtType = VIR_DOMAIN_VIRT_KVM;
43fe83
+            def->features |= (1 << VIR_DOMAIN_FEATURE_PAE);
43fe83
+        }
43fe83
     }
43fe83
 
43fe83
-    if (STRPREFIX(def->emulator, "qemu"))
43fe83
-        path = def->emulator;
43fe83
-    else
43fe83
-        path = strstr(def->emulator, "qemu");
43fe83
     if (def->virtType == VIR_DOMAIN_VIRT_KVM)
43fe83
         def->os.arch = qemuCaps->host.arch;
43fe83
-    else if (path &&
43fe83
-             STRPREFIX(path, "qemu-system-"))
43fe83
+    else if (STRPREFIX(path, "qemu-system-"))
43fe83
         def->os.arch = virArchFromString(path + strlen("qemu-system-"));
43fe83
     else
43fe83
         def->os.arch = VIR_ARCH_I686;
43fe83
@@ -10796,6 +10793,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
43fe83
         (def->os.arch == VIR_ARCH_X86_64))
43fe83
         def->features |= (1 << VIR_DOMAIN_FEATURE_ACPI)
43fe83
         /*| (1 << VIR_DOMAIN_FEATURE_APIC)*/;
43fe83
+
43fe83
 #define WANT_VALUE()                                                   \
43fe83
     const char *val = progargv[++i];                                   \
43fe83
     if (!val) {                                                        \
43fe83
-- 
43fe83
1.8.3.2
43fe83