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

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

 



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@xxxxxxxxxx    +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]