]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Don't accept dummy values for <memoryBacking/> attributes
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 21 Feb 2017 16:24:17 +0000 (17:24 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 22 Feb 2017 08:11:33 +0000 (09:11 +0100)
Our virSomeEnumTypeFromString() functions return either the value
of item from the enum or -1 on error. Usually however the value 0
means 'this value is not set in the domain XML, use some sensible
default'. Therefore, we don't accept corresponding string in
domain XML, for instance:

<memoryBacking>
  <source mode="none"/>
  <access mode="default"/>
  <allocation mode="none"/>
</memoryBacking>

should be rejected as invalid XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c

index 79bdbdf50ce62076ece4aeb7ffc4cb469cda3953..f718b9abc5133d6050be3027a7bcf109fd7377d3 100644 (file)
@@ -16724,7 +16724,7 @@ virDomainDefParseXML(xmlDocPtr xml,
 
     tmp = virXPathString("string(./memoryBacking/source/@type)", ctxt);
     if (tmp) {
-        if ((def->mem.source = virDomainMemorySourceTypeFromString(tmp)) < 0) {
+        if ((def->mem.source = virDomainMemorySourceTypeFromString(tmp)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown memoryBacking/source/type '%s'"), tmp);
             goto error;
@@ -16734,7 +16734,7 @@ virDomainDefParseXML(xmlDocPtr xml,
 
     tmp = virXPathString("string(./memoryBacking/access/@mode)", ctxt);
     if (tmp) {
-        if ((def->mem.access = virDomainMemoryAccessTypeFromString(tmp)) < 0) {
+        if ((def->mem.access = virDomainMemoryAccessTypeFromString(tmp)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown memoryBacking/access/mode '%s'"), tmp);
             goto error;
@@ -16744,7 +16744,7 @@ virDomainDefParseXML(xmlDocPtr xml,
 
     tmp = virXPathString("string(./memoryBacking/allocation/@mode)", ctxt);
     if (tmp) {
-        if ((def->mem.allocation = virDomainMemoryAllocationTypeFromString(tmp)) < 0) {
+        if ((def->mem.allocation = virDomainMemoryAllocationTypeFromString(tmp)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown memoryBacking/allocation/mode '%s'"), tmp);
             goto error;