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

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

 



---
 tools/virsh.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

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';
         xmlBufferFree(xml_buf);
     }
     return ret;
-- 
1.7.7.3

--
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]