提交 6a373fb2 编写于 作者: E Eric Blake

qemu: only parse basename when determining emulator properties

'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: NEric Blake <eblake@redhat.com>
上级 744fb508
......@@ -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",
......
......@@ -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) { \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册