render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 044e5a7db716235c167f76974d4bd7566248cf9a Mon Sep 17 00:00:00 2001
Message-Id: <044e5a7db716235c167f76974d4bd7566248cf9a@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Mon, 16 Mar 2020 22:11:45 +0100
Subject: [PATCH] qemuDomainSecretAESSetup: Automatically free non-secret
 locals
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Use g_autofree for the ciphertext and init vector as they are not
secret and thus don't have to be cleared and use g_new0 to allocate the
iv for parity.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 88126d5f0ec3899dbc3bc223d120de159ded9dca)

 Conflicts:
    src/qemu/qemu_domain.c:
    20fa2bc6e52e01feaf39d12d38bcf8eaec4c9a46 was not backported
    and thus this patch also effectively backports the modification
    the patch mentioned above did to qemuDomainSecretAESSetup as it
    would not result in a clean backport.

https://bugzilla.redhat.com/show_bug.cgi?id=1804750
Message-Id: <6d4512020332b977f8de5843469e0d030f4f65d3.1584391726.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_domain.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index b77488026a..b26187659e 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1542,16 +1542,15 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
                          virSecretLookupTypeDefPtr seclookupdef,
                          bool isLuks)
 {
-    virConnectPtr conn;
+    g_autoptr(virConnect) conn = virGetConnectSecret();
     int ret = -1;
-    uint8_t *raw_iv = NULL;
+    g_autofree uint8_t *raw_iv = NULL;
     size_t ivlen = QEMU_DOMAIN_AES_IV_LEN;
     uint8_t *secret = NULL;
     size_t secretlen = 0;
-    uint8_t *ciphertext = NULL;
+    g_autofree uint8_t *ciphertext = NULL;
     size_t ciphertextlen = 0;
 
-    conn = virGetConnectSecret();
     if (!conn)
         return -1;
 
@@ -1559,14 +1558,13 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
     secinfo->s.aes.username = g_strdup(username);
 
     if (!(secinfo->s.aes.alias = qemuDomainGetSecretAESAlias(srcalias, isLuks)))
-        goto cleanup;
+        return -1;
 
-    if (VIR_ALLOC_N(raw_iv, ivlen) < 0)
-        goto cleanup;
+    raw_iv = g_new0(uint8_t, ivlen);
 
     /* Create a random initialization vector */
     if (virRandomBytes(raw_iv, ivlen) < 0)
-        goto cleanup;
+        return -1;
 
     /* Encode the IV and save that since qemu will need it */
     secinfo->s.aes.iv = g_base64_encode(raw_iv, ivlen);
@@ -1592,10 +1590,7 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
     ret = 0;
 
  cleanup:
-    VIR_DISPOSE_N(raw_iv, ivlen);
     VIR_DISPOSE_N(secret, secretlen);
-    VIR_DISPOSE_N(ciphertext, ciphertextlen);
-    virObjectUnref(conn);
     return ret;
 }
 
-- 
2.25.1