[libvirt] [PATCH] Fix Invalid write in virCryptoHashString()
Eric Blake
eblake at redhat.com
Wed Mar 12 21:51:32 UTC 2014
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140312/50775708/attachment-0001.sig>
More information about the libvir-list
mailing list