[libvirt] [PATCH] virsh: Null terminated the string memcpy from buffer explicitly

Eric Blake eblake at redhat.com
Thu Jun 14 11:16:17 UTC 2012


On 06/14/2012 05:09 AM, Osier Yang wrote:
> ---
>  tools/virsh.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)

A bit light on the commit message.  Does this solve an actual crash, or
does it just silence an overactive static code analyzer?

> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index 98305c0..4509020 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -15069,11 +15069,13 @@ cleanup:
>      VIR_FREE(device_type);
>      VIR_FREE(disk_type);
>      if (xml_buf) {
> -        if (VIR_ALLOC_N(ret, xmlBufferLength(xml_buf)) < 0) {
> +        int len = xmlBufferLength(xml_buf);
> +        if (VIR_ALLOC_N(ret, len + 1) < 0) {
>              virReportOOMError();
>              return NULL;
>          }
> -        memcpy(ret, (char *)xmlBufferContent(xml_buf), xmlBufferLength(xml_buf));
> +        memcpy(ret, (char *)xmlBufferContent(xml_buf), len);
> +        ret[len] = '\0';

At any rate, the conversion makes sense.  ACK, if you'll improve the
commit message.

-- 
Eric Blake   eblake at 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: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120614/7cfce4f4/attachment-0001.sig>


More information about the libvir-list mailing list