Re: [RFC PATCH 1/5] storage: encryption: Add deep copy function for storage encryption

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]