[libvirt] [PATCH v3 10/10] conf: Rework virDomainKeyWrapDefParseXML

Ján Tomko jtomko at redhat.com
Mon Mar 4 14:41:55 UTC 2019


On Fri, Mar 01, 2019 at 11:26:52AM -0500, John Ferlan wrote:
>Rewrite the code to make usage of some VIR_AUTOFREE logic.
>
>Suggested-by: Erik Skultety <eskultet at redhat.com>
>Signed-off-by: John Ferlan <jferlan at redhat.com>
>---
> src/conf/domain_conf.c | 22 ++++++++--------------
> 1 file changed, 8 insertions(+), 14 deletions(-)
>
>diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>index be6e223e78..05c2c9f34e 100644
>--- a/src/conf/domain_conf.c
>+++ b/src/conf/domain_conf.c
>@@ -1170,31 +1170,25 @@ static int
> virDomainKeyWrapDefParseXML(virDomainDefPtr def, xmlXPathContextPtr ctxt)
> {
>     size_t i;
>-    int ret = -1;
>     int n;
>     VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
>+    VIR_AUTOFREE(virDomainKeyWrapDefPtr) keywrap = NULL;
>
>     if ((n = virXPathNodeSet("./keywrap/cipher", ctxt, &nodes)) < 0)
>         return n;
>
>-    if (VIR_ALLOC(def->keywrap) < 0)
>-        goto cleanup;
>+    if (VIR_ALLOC(keywrap) < 0)
>+        return -1;
>
>     for (i = 0; i < n; i++) {
>-        if (virDomainKeyWrapCipherDefParseXML(def->keywrap, nodes[i]) < 0)
>-            goto cleanup;
>+        if (virDomainKeyWrapCipherDefParseXML(keywrap, nodes[i]) < 0)
>+            return -1;
>     }
>
>-    if (!def->keywrap->aes &&
>-        !def->keywrap->dea)
>-        VIR_FREE(def->keywrap);
>+    if (keywrap->aes || keywrap->dea)
>+        VIR_STEAL_PTR(def->keywrap, keywrap);
>

This is an odd condition (but preserving existing oddness)

For any invalid or duplicate <cipher> elements virDomainKeyWrapCipherDefParseXML
would return an error, so the only way to get here without satisfying
the conditions is when n = 0.

But the patch itself is correct.
Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano

>-    ret = 0;
>-
>- cleanup:
>-    if (ret < 0)
>-        VIR_FREE(def->keywrap);
>-    return ret;
>+    return 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190304/f1a51f73/attachment-0001.sig>


More information about the libvir-list mailing list