d76c62
From 914a920180c9803a57c06bd71f5270724c1dc900 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <914a920180c9803a57c06bd71f5270724c1dc900@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Fri, 20 Mar 2020 10:28:52 +0100
d76c62
Subject: [PATCH] virStorageEncryptionSecretCopy: Properly copy internals
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
virStorageEncryptionSecretPtr may have a string inside it, thus we must
d76c62
copy the string too. Use virSecretLookupDefCopy to do that.
d76c62
d76c62
Caused by non-obvious code introduced in 756b46ddd24 and later 47e88b33b
d76c62
which added a string that needed to be copied.
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1814923
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
d76c62
(cherry picked from commit 299796328c34a30295d6cdc7ebce5d65843e921f)
d76c62
Message-Id: <2e350bb771f75d9fd068f69a595401907d92ca33.1584696274.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/util/virstorageencryption.c | 8 +++-----
d76c62
 1 file changed, 3 insertions(+), 5 deletions(-)
d76c62
d76c62
diff --git a/src/util/virstorageencryption.c b/src/util/virstorageencryption.c
d76c62
index 74836d4a00..6765fdc23a 100644
d76c62
--- a/src/util/virstorageencryption.c
d76c62
+++ b/src/util/virstorageencryption.c
d76c62
@@ -85,12 +85,10 @@ virStorageEncryptionFree(virStorageEncryptionPtr enc)
d76c62
 static virStorageEncryptionSecretPtr
d76c62
 virStorageEncryptionSecretCopy(const virStorageEncryptionSecret *src)
d76c62
 {
d76c62
-    virStorageEncryptionSecretPtr ret;
d76c62
-
d76c62
-    if (VIR_ALLOC(ret) < 0)
d76c62
-        return NULL;
d76c62
+    virStorageEncryptionSecretPtr ret = g_new0(virStorageEncryptionSecret, 1);
d76c62
 
d76c62
-    memcpy(ret, src, sizeof(*src));
d76c62
+    ret->type = src->type;
d76c62
+    virSecretLookupDefCopy(&ret->seclookupdef, &src->seclookupdef);
d76c62
 
d76c62
     return ret;
d76c62
 }
d76c62
-- 
d76c62
2.25.1
d76c62