+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
}
+/**
+ * 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
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);
}
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,
ADD_ARG_LIT(emulator);
ADD_ARG_LIT("-S");
- ADD_ARG_LIT("-M");
- ADD_ARG_LIT(vm->def->os.machine);
+
+ /* 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");