[libvirt] [PATCH] conf: Don't accept dummy values for <memoryBacking/> attributes

Michal Privoznik posted 1 patch 170 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1b961f731daa266c46a215b2f77bcfe6d253a273.1487694702.git.mprivozn@redhat.com
src/conf/domain_conf.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

[libvirt] [PATCH] conf: Don't accept dummy values for <memoryBacking/> attributes

Posted by Michal Privoznik 170 weeks ago
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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 79bdbdf50..f718b9abc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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;
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] conf: Don't accept dummy values for <memoryBacking/> attributes

Posted by Martin Kletzander 170 weeks ago
On Tue, Feb 21, 2017 at 05:31:42PM +0100, Michal Privoznik wrote:
>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 | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>

ACK
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list