virStorageEncryptionSecretCopy: Properly copy internals

virStorageEncryptionSecretPtr may have a string inside it, thus we must
copy the string too. Use virSecretLookupDefCopy to do that.

Caused by non-obvious code introduced in 756b46ddd2 and later 47e88b33b
which added a string that needed to be copied.

https://bugzilla.redhat.com/show_bug.cgi?id=1814923

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2020-03-19 15:38:06 +01:00
parent 02f909b8a6
commit 299796328c

View File

@ -85,12 +85,10 @@ virStorageEncryptionFree(virStorageEncryptionPtr enc)
static virStorageEncryptionSecretPtr static virStorageEncryptionSecretPtr
virStorageEncryptionSecretCopy(const virStorageEncryptionSecret *src) virStorageEncryptionSecretCopy(const virStorageEncryptionSecret *src)
{ {
virStorageEncryptionSecretPtr ret; virStorageEncryptionSecretPtr ret = g_new0(virStorageEncryptionSecret, 1);
if (VIR_ALLOC(ret) < 0) ret->type = src->type;
return NULL; virSecretLookupDefCopy(&ret->seclookupdef, &src->seclookupdef);
memcpy(ret, src, sizeof(*src));
return ret; return ret;
} }