[libvirt] [PATCH 3/4] virCommand: Make virCommandPassFDGetFDIndex fail if passed command is in error state

Daniel P. Berrangé berrange at redhat.com
Tue May 14 13:44:58 UTC 2019


On Tue, May 14, 2019 at 11:24:11AM +0200, Michal Privoznik wrote:
> The idea of virCommand* APIs is that a possible error that
> occurred while constructing cmd line is kept in virCommand
> struct. If that's the case all subsequent calls to virCommand*()
> are NO-OPs or they return an error. Well,
> virCommandPassFDGetFDIndex() is not honoring that.

This is the flaw that caused the crash I reported yesterday when
running qemuxml2argvtest with ENOMEM simulation active.

> 
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  src/util/vircommand.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/util/vircommand.c b/src/util/vircommand.c
> index 9e99697c55..8695c98d1b 100644
> --- a/src/util/vircommand.c
> +++ b/src/util/vircommand.c
> @@ -1034,6 +1034,9 @@ virCommandPassFDGetFDIndex(virCommandPtr cmd, int fd)
>  {
>      size_t i = 0;
>  
> +    if (!cmd || cmd->has_error)
> +        return -1;
> +
>      while (i < cmd->npassfd) {
>          if (cmd->passfd[i].fd == fd)
>              return i;


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the libvir-list mailing list