render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
a41c76
From 044e5a7db716235c167f76974d4bd7566248cf9a Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <044e5a7db716235c167f76974d4bd7566248cf9a@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Mon, 16 Mar 2020 22:11:45 +0100
a41c76
Subject: [PATCH] qemuDomainSecretAESSetup: Automatically free non-secret
a41c76
 locals
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Use g_autofree for the ciphertext and init vector as they are not
a41c76
secret and thus don't have to be cleared and use g_new0 to allocate the
a41c76
iv for parity.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 88126d5f0ec3899dbc3bc223d120de159ded9dca)
a41c76
a41c76
 Conflicts:
a41c76
    src/qemu/qemu_domain.c:
a41c76
    20fa2bc6e52e01feaf39d12d38bcf8eaec4c9a46 was not backported
a41c76
    and thus this patch also effectively backports the modification
a41c76
    the patch mentioned above did to qemuDomainSecretAESSetup as it
a41c76
    would not result in a clean backport.
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
a41c76
Message-Id: <6d4512020332b977f8de5843469e0d030f4f65d3.1584391726.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_domain.c | 17 ++++++-----------
a41c76
 1 file changed, 6 insertions(+), 11 deletions(-)
a41c76
a41c76
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
a41c76
index b77488026a..b26187659e 100644
a41c76
--- a/src/qemu/qemu_domain.c
a41c76
+++ b/src/qemu/qemu_domain.c
a41c76
@@ -1542,16 +1542,15 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
a41c76
                          virSecretLookupTypeDefPtr seclookupdef,
a41c76
                          bool isLuks)
a41c76
 {
a41c76
-    virConnectPtr conn;
a41c76
+    g_autoptr(virConnect) conn = virGetConnectSecret();
a41c76
     int ret = -1;
a41c76
-    uint8_t *raw_iv = NULL;
a41c76
+    g_autofree uint8_t *raw_iv = NULL;
a41c76
     size_t ivlen = QEMU_DOMAIN_AES_IV_LEN;
a41c76
     uint8_t *secret = NULL;
a41c76
     size_t secretlen = 0;
a41c76
-    uint8_t *ciphertext = NULL;
a41c76
+    g_autofree uint8_t *ciphertext = NULL;
a41c76
     size_t ciphertextlen = 0;
a41c76
 
a41c76
-    conn = virGetConnectSecret();
a41c76
     if (!conn)
a41c76
         return -1;
a41c76
 
a41c76
@@ -1559,14 +1558,13 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
a41c76
     secinfo->s.aes.username = g_strdup(username);
a41c76
 
a41c76
     if (!(secinfo->s.aes.alias = qemuDomainGetSecretAESAlias(srcalias, isLuks)))
a41c76
-        goto cleanup;
a41c76
+        return -1;
a41c76
 
a41c76
-    if (VIR_ALLOC_N(raw_iv, ivlen) < 0)
a41c76
-        goto cleanup;
a41c76
+    raw_iv = g_new0(uint8_t, ivlen);
a41c76
 
a41c76
     /* Create a random initialization vector */
a41c76
     if (virRandomBytes(raw_iv, ivlen) < 0)
a41c76
-        goto cleanup;
a41c76
+        return -1;
a41c76
 
a41c76
     /* Encode the IV and save that since qemu will need it */
a41c76
     secinfo->s.aes.iv = g_base64_encode(raw_iv, ivlen);
a41c76
@@ -1592,10 +1590,7 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
a41c76
     ret = 0;
a41c76
 
a41c76
  cleanup:
a41c76
-    VIR_DISPOSE_N(raw_iv, ivlen);
a41c76
     VIR_DISPOSE_N(secret, secretlen);
a41c76
-    VIR_DISPOSE_N(ciphertext, ciphertextlen);
a41c76
-    virObjectUnref(conn);
a41c76
     return ret;
a41c76
 }
a41c76
 
a41c76
-- 
a41c76
2.25.1
a41c76