From 0befde5c74a0d886f4683d1fb669641fbe053cc2 Mon Sep 17 00:00:00 2001 Message-Id: <0befde5c74a0d886f4683d1fb669641fbe053cc2.1380112457.git.jdenemar@redhat.com> From: Eric Blake Date: Mon, 23 Sep 2013 11:10:03 -0600 Subject: [PATCH] qemu: only parse basename when determining emulator properties https://bugzilla.redhat.com/show_bug.cgi?id=1010617 '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 (cherry picked from commit 6a373fb2c95300d632a7371c893a301364f8dcb5) Signed-off-by: Jiri Denemark --- 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 566940c..b46381f 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 6a6b3cd..dd63e01 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" @@ -10765,29 +10766,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; @@ -10796,6 +10793,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.2