On 03/12/2014 03:44 PM, Nehal J Wani wrote:
> While running vircryptotest, it was found that valgrind pointed out the
> following error:
> 
> ==27453== Invalid write of size 1
> ==27453==    at 0x4C7D7C9: virCryptoHashString (vircrypto.c:76)

> 
> ---
> The errors go away, if I either do:
> Line 76: (*output)[hashstrlen - 1] = '\0';

This is correct, since we  initialized hashstrlen to be strlen()+1 in
the first place.

> or
> Line 61: if (VIR_ALLOC_N(*output, hashstrlen + 1) < 0)
> But the second one seems less harmful, as anyway we are going to free
> that memory.

Overallocating by 2 is pointless.  But so is writing a trailing NUL, as
the string is already zero-initialized by VIR_ALLOC_N.

So the CORRECT fix, which I am pushing shortly, is to just delete the
redundant line:
    (*output)[hashstrlen] = '\0';


-- 
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@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to