[libvirt] [PATCH] conf: Don't assign value from ..TypeFromString directly to enum

Peter Krempa posted 1 patch 6 years, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/684236690f49befaa1641da4bdbffc4ed3e2e087.1495182477.git.pkrempa@redhat.com
src/conf/domain_conf.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
[libvirt] [PATCH] conf: Don't assign value from ..TypeFromString directly to enum
Posted by Peter Krempa 6 years, 10 months ago
Enums are unsigned, so it's impossible to check whether the helper
returned -1 for invalid conversions.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1452454
---
 src/conf/domain_conf.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9eba70a95..54d87666b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14083,6 +14083,7 @@ virDomainMemoryDefParseXML(xmlNodePtr memdevNode,
     xmlNodePtr save = ctxt->node;
     xmlNodePtr node;
     virDomainMemoryDefPtr def;
+    int accessval;

     ctxt->node = memdevNode;

@@ -14102,12 +14103,14 @@ virDomainMemoryDefParseXML(xmlNodePtr memdevNode,
     }
     VIR_FREE(tmp);

-    tmp = virXMLPropString(memdevNode, "access");
-    if (tmp &&
-        (def->access = virDomainMemoryAccessTypeFromString(tmp)) <= 0) {
-        virReportError(VIR_ERR_XML_ERROR,
-                       _("invalid access mode '%s'"), tmp);
-        goto error;
+    if ((tmp = virXMLPropString(memdevNode, "access"))) {
+        if ((accessval = virDomainMemoryAccessTypeFromString(tmp)) <= 0) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("invalid access mode '%s'"), tmp);
+            goto error;
+        }
+
+        def->access = accessval;
     }
     VIR_FREE(tmp);

-- 
2.12.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] conf: Don't assign value from ..TypeFromString directly to enum
Posted by Pavel Hrdina 6 years, 10 months ago
On Fri, May 19, 2017 at 10:27:57AM +0200, Peter Krempa wrote:
> Enums are unsigned, so it's impossible to check whether the helper
> returned -1 for invalid conversions.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1452454
> ---
>  src/conf/domain_conf.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] conf: Don't assign value from ..TypeFromString directly to enum
Posted by Ján Tomko 6 years, 10 months ago
On Fri, May 19, 2017 at 10:27:57AM +0200, Peter Krempa wrote:
>Enums are unsigned, so it's impossible to check whether the helper
>returned -1 for invalid conversions.
>
>Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1452454
>---
> src/conf/domain_conf.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
>diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>index 9eba70a95..54d87666b 100644
>--- a/src/conf/domain_conf.c
>+++ b/src/conf/domain_conf.c
>@@ -14083,6 +14083,7 @@ virDomainMemoryDefParseXML(xmlNodePtr memdevNode,
>     xmlNodePtr save = ctxt->node;
>     xmlNodePtr node;
>     virDomainMemoryDefPtr def;
>+    int accessval;

I'd rather go with 'val', so that the variable can be reused for other
attributes, just like 'tmp'.
>
>     ctxt->node = memdevNode;
>

ACK

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