[libvirt] [PATCH 1/3] vircommand: Ensure buffers are NULL-terminated

Andrea Bolognani abologna at redhat.com
Tue Feb 5 15:16:21 UTC 2019


The memory allocated by VIR_REALLOC_N() is uninitialized,
which means it's not possible to figure out whether any
output was produced at all after the fact.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 src/util/vircommand.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index d965068369..6e9e56d0c0 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2057,11 +2057,13 @@ virCommandProcessIO(virCommandPtr cmd)
         outfd = cmd->outfd;
         if (VIR_REALLOC_N(*cmd->outbuf, 1) < 0)
             ret = -1;
+        *cmd->outbuf[0] = '\0';
     }
     if (cmd->errbuf) {
         errfd = cmd->errfd;
         if (VIR_REALLOC_N(*cmd->errbuf, 1) < 0)
             ret = -1;
+        *cmd->errbuf[0] = '\0';
     }
     if (ret == -1)
         goto cleanup;
-- 
2.20.1




More information about the libvir-list mailing list