Fix crash using bogus arch in QEMU

This commit is contained in:
Daniel P. Berrange 2009-01-30 17:12:28 +00:00
parent 896761e5c7
commit 3cb55cb51f
5 changed files with 58 additions and 3 deletions

View File

@ -1,3 +1,13 @@
Fri Jan 30 16:12:22 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
Fix crash when using bogus arch type
* src/capabilities.c, src/capabilities.h: Add method to query
for supported arch+ostype combo
* src/domain_conf.c: Validate requested arch+ostype against
supported capabilities
* src/qemu_conf.c: Sanity check to avoid deferencing NULL
machine type
Fri Jan 30 16:58:22 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
Misc QEMU driver startup fixes

View File

@ -432,6 +432,30 @@ virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
}
/**
* virCapabilitiesSupportsGuestOSType:
* @caps: capabilities to query
* @ostype: OS type to search for (eg 'hvm', 'xen')
* @arch: Architecture to search for (eg, 'i686', 'x86_64')
*
* Returns non-zero if the capabilities support the
* requested operating system type
*/
extern int
virCapabilitiesSupportsGuestArch(virCapsPtr caps,
const char *ostype,
const char *arch)
{
int i;
for (i = 0 ; i < caps->nguests ; i++) {
if (STREQ(caps->guests[i]->ostype, ostype) &&
STREQ(caps->guests[i]->arch.name, arch))
return 1;
}
return 0;
}
/**
* virCapabilitiesDefaultGuestArch:
* @caps: capabilities to query

View File

@ -162,6 +162,12 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest,
extern int
virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
const char *ostype);
extern int
virCapabilitiesSupportsGuestArch(virCapsPtr caps,
const char *ostype,
const char *arch);
extern const char *
virCapabilitiesDefaultGuestArch(virCapsPtr caps,
const char *ostype);

View File

@ -2038,7 +2038,14 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
}
def->os.arch = virXPathString(conn, "string(./os/type[1]/@arch)", ctxt);
if (!def->os.arch) {
if (def->os.arch) {
if (!virCapabilitiesSupportsGuestArch(caps, def->os.type, def->os.arch)) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("os type '%s' & arch '%s' combination is not supported"),
def->os.type, def->os.arch);
goto error;
}
} else {
const char *defaultArch = virCapabilitiesDefaultGuestArch(caps, def->os.type);
if (defaultArch == NULL) {
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,

View File

@ -837,8 +837,16 @@ int qemudBuildCommandLine(virConnectPtr conn,
ADD_ARG_LIT(emulator);
ADD_ARG_LIT("-S");
/* This should *never* be NULL, since we always provide
* a machine in the capabilities data for QEMU. So this
* check is just here as a safety in case the unexpected
* happens */
if (vm->def->os.machine) {
ADD_ARG_LIT("-M");
ADD_ARG_LIT(vm->def->os.machine);
}
if (disableKQEMU)
ADD_ARG_LIT("-no-kqemu");
ADD_ARG_LIT("-m");