]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuDomainSecretAESSetup: Automatically free non-secret locals
authorPeter Krempa <pkrempa@redhat.com>
Mon, 16 Mar 2020 09:13:38 +0000 (10:13 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 Mar 2020 12:04:17 +0000 (13:04 +0100)
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>
src/qemu/qemu_domain.c

index 7c962fb062716d5dd1ad6bead87ff9f36f7e24e6..e33d3099d6696b314c7d40c9ebd56580939ea37b 100644 (file)
@@ -1536,11 +1536,11 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
 {
     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;
 
     if (!conn)
@@ -1550,14 +1550,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);
@@ -1583,9 +1582,7 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
     ret = 0;
 
  cleanup:
-    VIR_DISPOSE_N(raw_iv, ivlen);
     VIR_DISPOSE_N(secret, secretlen);
-    VIR_DISPOSE_N(ciphertext, ciphertextlen);
     return ret;
 }