From 53a699a07b118af2cd1c4625588737095c125b2f Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 10 Jan 2014 17:18:03 +0000 Subject: [PATCH] Exercise the ABI stability check code in test suite Any test suite which involves a virDomainDefPtr should call virDomainDefCheckABIStability with itself just as a basic sanity check that the identity-comparison always succeeds. This would have caught the recent NULL pointer access crash. Make sure we cope with def->name being NULL since the VMWare config parser produces NULL names. Signed-off-by: Daniel P. Berrange --- src/conf/domain_conf.c | 2 +- tests/lxcxml2xmltest.c | 5 +++++ tests/qemuargv2xmltest.c | 5 +++++ tests/qemuxml2argvtest.c | 5 +++++ tests/qemuxml2xmltest.c | 5 +++++ tests/qemuxmlnstest.c | 5 +++++ tests/sexpr2xmltest.c | 5 +++++ tests/vmx2xmltest.c | 5 +++++ tests/xmconfigtest.c | 5 +++++ tests/xml2sexprtest.c | 5 +++++ tests/xml2vmxtest.c | 5 +++++ 11 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 416d96e668..c1dd5987d4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13761,7 +13761,7 @@ virDomainDefCheckABIStability(virDomainDefPtr src, * don't get silently re-named through the backdoor when passing * custom XML into various APIs, since this would create havoc */ - if (STRNEQ(src->name, dst->name)) { + if (STRNEQ_NULLABLE(src->name, dst->name)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Target domain name '%s' does not match source '%s'"), dst->name, src->name); diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index c6bb706157..af50dc5ebf 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -41,6 +41,11 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) live ? 0 : VIR_DOMAIN_XML_INACTIVE))) goto fail; + if (!virDomainDefCheckABIStability(def, def)) { + fprintf(stderr, "ABI stability check failed on %s", inxml); + goto fail; + } + if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE))) goto fail; diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c index 0bf4c37d96..1b13fcc8db 100644 --- a/tests/qemuargv2xmltest.c +++ b/tests/qemuargv2xmltest.c @@ -61,6 +61,11 @@ static int testCompareXMLToArgvFiles(const char *xml, } VIR_FREE(log); + if (!virDomainDefCheckABIStability(vmdef, vmdef)) { + fprintf(stderr, "ABI stability check failed on %s", xml); + goto fail; + } + if (!(actualxml = virDomainDefFormat(vmdef, 0))) goto fail; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b90f0e79c2..b0cfa608c0 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -289,6 +289,11 @@ static int testCompareXMLToArgvFiles(const char *xml, goto out; } + if (!virDomainDefCheckABIStability(vmdef, vmdef)) { + fprintf(stderr, "ABI stability check failed on %s", xml); + goto out; + } + if (virQEMUCapsGet(extraFlags, QEMU_CAPS_DOMID)) vmdef->id = 6; else diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 89de0c951c..41d19047d0 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -41,6 +41,11 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) QEMU_EXPECTED_VIRT_TYPES, flags))) goto fail; + if (!virDomainDefCheckABIStability(def, def)) { + fprintf(stderr, "ABI stability check failed on %s", inxml); + goto fail; + } + if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE | flags))) goto fail; diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c index 2093e1e1b2..9426bf7571 100644 --- a/tests/qemuxmlnstest.c +++ b/tests/qemuxmlnstest.c @@ -59,6 +59,11 @@ static int testCompareXMLToArgvFiles(const char *xml, VIR_DOMAIN_XML_INACTIVE))) goto fail; + if (!virDomainDefCheckABIStability(vmdef, vmdef)) { + fprintf(stderr, "ABI stability check failed on %s", xml); + goto fail; + } + /* * For test purposes, we may want to fake emulator's output by providing * our own script instead of a real emulator. For this to work we need to diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c index f8b0661364..c2710c27d7 100644 --- a/tests/sexpr2xmltest.c +++ b/tests/sexpr2xmltest.c @@ -60,6 +60,11 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) if (!(def = xenParseSxprString(sexprData, xendConfigVersion, tty, vncport))) goto fail; + if (!virDomainDefCheckABIStability(def, def)) { + fprintf(stderr, "ABI stability check failed on %s", xml); + goto fail; + } + if (!(gotxml = virDomainDefFormat(def, 0))) goto fail; diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 13515f0883..5c3b60e22d 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -88,6 +88,11 @@ testCompareFiles(const char *vmx, const char *xml) if (!(def = virVMXParseConfig(&ctx, xmlopt, vmxData))) goto cleanup; + if (!virDomainDefCheckABIStability(def, def)) { + fprintf(stderr, "ABI stability check failed on %s", vmx); + goto cleanup; + } + if (!(formatted = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE))) goto cleanup; diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c index c8014e1d8e..05903333bd 100644 --- a/tests/xmconfigtest.c +++ b/tests/xmconfigtest.c @@ -77,6 +77,11 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion) VIR_DOMAIN_XML_INACTIVE))) goto fail; + if (!virDomainDefCheckABIStability(def, def)) { + fprintf(stderr, "ABI stability check failed on %s", xml); + goto fail; + } + if (!(conf = xenFormatXM(conn, def, xendConfigVersion))) goto fail; diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c index a4d2b14218..deb2fced3b 100644 --- a/tests/xml2sexprtest.c +++ b/tests/xml2sexprtest.c @@ -41,6 +41,11 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) VIR_DOMAIN_XML_INACTIVE))) goto fail; + if (!virDomainDefCheckABIStability(def, def)) { + fprintf(stderr, "ABI stability check failed on %s", xml); + goto fail; + } + if (!(gotsexpr = xenFormatSxpr(NULL, def, xendConfigVersion))) goto fail; diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 2f2db6070e..242b854130 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -97,6 +97,11 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) goto failure; } + if (!virDomainDefCheckABIStability(def, def)) { + fprintf(stderr, "ABI stability check failed on %s", xml); + goto failure; + } + formatted = virVMXFormatConfig(&ctx, xmlopt, def, virtualHW_version); if (formatted == NULL) {