[libvirt] [PATCH] Fix misc bugs in virCommandPtr

Eric Blake eblake at redhat.com
Tue Mar 15 14:03:09 UTC 2011


On 03/15/2011 06:32 AM, Daniel P. Berrange wrote:
> The virCommandNewArgs() method would free the virCommandPtr
> if it failed to add the args. This meant errors reported in
> virCommandAddArgSet() were lost. Simply removing the check
> for errors from the constructor means they can be reported
> correctly later
> 
> The virCommandAddEnvPassCommon() method failed to check for
> errors before reallocating the cmd->env array, causing a
> potential SEGV if cmd was NULL
> 
> The virCommandAddArgSet() method needs to validate that at
> least 1 element in 'val's parameter is non-NULL, otherwise
> code like
> 
>     cmd = virCommandNew(binary)
>     virCommandAddAtg(cmd, "foo")
> 
> Would end up trying todo  execve("foo"), if binary was
> NULL.

Well, technically virCommandNew is ATTRIBUTE_NONNULL(1), so we would
have caught this via clang (gcc's not quite as smart as clang at
enforcing that parameter).  But it doesn't hurt to be safe.

> ---
>  src/util/command.c |   13 ++++++++-----
>  1 files changed, 8 insertions(+), 5 deletions(-)

ACK to all three cleanups.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110315/03057a83/attachment-0001.sig>


More information about the libvir-list mailing list