[libvirt] [PATCH 4/3] conf: Resolve Coverity NEGATIVE_RETURNS

Laine Stump laine at laine.org
Mon May 25 14:00:16 UTC 2015


On 05/18/2015 09:21 AM, John Ferlan wrote:
> Commit id '73eda710' added virDomainKeyWrapDefParseXML which uses
> virXPathNodeSet, but does not handle a -1 return thus causing a possible
> loop condition exit problem later when the return value is used.
>
> Change the logic to return the value from virXPathNodeSet if <= 0
>
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
>  src/conf/domain_conf.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index e2b1194..a97e640 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -940,8 +940,8 @@ virDomainKeyWrapDefParseXML(virDomainDefPtr def, xmlXPathContextPtr ctxt)
>      xmlNodePtr *nodes = NULL;
>      int n;
>  
> -    if (!(n = virXPathNodeSet("./keywrap/cipher", ctxt, &nodes)))
> -        return 0;
> +    if ((n = virXPathNodeSet("./keywrap/cipher", ctxt, &nodes)) < 0)
> +        return n;

Seemed a bit strange at first (since the n == 0 case now continues
instead of returning immediately), but in the end it makes sense - if n
is 0, you end up allocating keywrap, never going through the loop, then
freeing keywrap and returning 0, to the result is the same as before.

ACK.

>  
>      if (VIR_ALLOC(def->keywrap) < 0)
>          goto cleanup;




More information about the libvir-list mailing list