[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] consolidate virXPathNodeSet()



On Wed, Oct 21, 2009 at 05:24:03PM +0200, Daniel Veillard wrote:
>   While reviewing Rich last patch I was afraid that virXPathNodeSet()
> could return -1 when doing an evaluation failure. It is based on
> xmlXPathEval() from libxml2 whose behaviour is to possibly return NULL
> on XPath evaluation failure independantly of the kind of failure:
> 
>     http://xmlsoft.org/html/libxml-xpath.html#xmlXPathEval
> 
>   I suggest to apply this patch to make sure we always return 0
> unless the returned XPath type is of the wrong type (meaning the
> query passed didn't evaluate to a node set and code must be fixed)

ACK


> diff --git a/src/util/xml.c b/src/util/xml.c
> index 4118d2a..4fa443d 100644
> --- a/src/util/xml.c
> +++ b/src/util/xml.c
> @@ -490,11 +490,16 @@ virXPathNodeSet(virConnectPtr conn,
>      relnode = ctxt->node;
>      obj = xmlXPathEval(BAD_CAST xpath, ctxt);
>      ctxt->node = relnode;
> -    if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
> -        (obj->nodesetval == NULL) || (obj->nodesetval->nodeNr < 0)) {
> +    if (obj == NULL)
> +        return(0);
> +    if (obj->type != XPATH_NODESET) {
>          xmlXPathFreeObject(obj);
>          return (-1);
>      }
> +    if ((obj->nodesetval == NULL)  || (obj->nodesetval->nodeNr < 0)) {
> +        xmlXPathFreeObject(obj);
> +        return (0);
> +    }
>  
>      ret = obj->nodesetval->nodeNr;
>      if (list != NULL && ret) {

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]