mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-08 22:39:56 +00:00
vircommand: Ensure buffers are NULL-terminated
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. Since we don't care about the previous contents of buffers, if any, use VIR_FREE() followed by VIR_ALLOC_N() instead. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
0b856db8ab
commit
1d2a62b2e0
@ -2055,12 +2055,14 @@ virCommandProcessIO(virCommandPtr cmd)
|
|||||||
* results accumulated over a prior run of the same command. */
|
* results accumulated over a prior run of the same command. */
|
||||||
if (cmd->outbuf) {
|
if (cmd->outbuf) {
|
||||||
outfd = cmd->outfd;
|
outfd = cmd->outfd;
|
||||||
if (VIR_REALLOC_N(*cmd->outbuf, 1) < 0)
|
VIR_FREE(*cmd->outbuf);
|
||||||
|
if (VIR_ALLOC_N(*cmd->outbuf, 1) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
if (cmd->errbuf) {
|
if (cmd->errbuf) {
|
||||||
errfd = cmd->errfd;
|
errfd = cmd->errfd;
|
||||||
if (VIR_REALLOC_N(*cmd->errbuf, 1) < 0)
|
VIR_FREE(*cmd->errbuf);
|
||||||
|
if (VIR_ALLOC_N(*cmd->errbuf, 1) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user