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

Osier Yang jyang at redhat.com
Thu Jun 14 11:09:53 UTC 2012


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




More information about the libvir-list mailing list