
On 06/12/2014 09:02 AM, Peter Krempa wrote:
--- src/util/virstorageencryption.c | 39 +++++++++++++++++++++++++++++++++++++++ src/util/virstorageencryption.h | 2 ++ 2 files changed, 41 insertions(+)
I've definitely been wishing for this; as our struct gets more complicated, piece-wise transfers into a temporary will not be robust, while copying into a temporary can be. Did you need to export the new symbol in libvirt_private.syms?
+virStorageEncryptionPtr +virStorageEncryptionCopy(const virStorageEncryption *src) +{ + virStorageEncryptionPtr ret; + size_t i; + + if (VIR_ALLOC(ret) < 0) + return NULL; + + ret->nsecrets = src->nsecrets;
Swap this line...
+ + if (VIR_ALLOC_N(ret->secrets, ret->nsecrets) < 0) + goto error;
...here, and use src->nsecrets instead of ret->nsecrets in the VIR_ALLOC_N. Why? Because if VIR_ALLOC_N fails, the error label calls virStorageEncryptionFree(ret), but that function blindly assumes that ret->nsecrets is valid and tries to dereference memory. You forgot: ret->format = src->format;
+++ b/src/util/virstorageencryption.h @@ -61,6 +61,8 @@ struct _virStorageEncryption { virStorageEncryptionSecretPtr *secrets; };
+virStorageEncryptionPtr virStorageEncryptionCopy(const virStorageEncryption *src);
add ATTRIBUTE_NONNULL(1), since we blindly dereference src. ACK with problems fixed. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org