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

Re: [libvirt] [PATCH 5/6] conf: Add helper to convert list of virDomains to a list of virDomainObjs



On Mon, May 11, 2015 at 06:33:00 -0400, John Ferlan wrote:
> 
> 
> On 04/30/2015 08:44 AM, Peter Krempa wrote:
> > Add virDomainObjListConvert that will take a list of virDomains, apply
> > filters and return a list of virDomainObjs.
> > ---
> >  src/conf/domain_conf.c   | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  src/conf/domain_conf.h   |  9 ++++++++
> >  src/libvirt_private.syms |  1 +
> >  3 files changed, 64 insertions(+)
> > 
> > diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> > index 66fe470..73dc33f 100644
> > --- a/src/conf/domain_conf.c
> > +++ b/src/conf/domain_conf.c
> > @@ -23072,6 +23072,60 @@ virDomainObjListCollect(virDomainObjListPtr domlist,
> > 
> > 
> >  int
> > +virDomainObjListConvert(virDomainObjListPtr domlist,
> > +                        virConnectPtr conn,
> > +                        virDomainPtr *doms,
> > +                        size_t ndoms,
> > +                        virDomainObjPtr **vms,
> > +                        size_t *nvms,
> > +                        virDomainObjListACLFilter filter,
> > +                        unsigned int flags,
> > +                        bool skip_missing)
> > +{
> > +    char uuidstr[VIR_UUID_STRING_BUFLEN];
> > +    virDomainObjPtr vm;
> > +    size_t i;
> > +
> > +    *nvms = 0;
> > +    *vms = NULL;
> > +
> > +    virObjectLock(domlist);
> > +    for (i = 0; i < ndoms; i++) {
> > +        virDomainPtr dom = doms[i];
> > +
> > +        virUUIDFormat(dom->uuid, uuidstr);
> > +
> > +        if (!(vm = virHashLookup(domlist->objs, uuidstr))) {
> > +            if (!skip_missing) {
> > +                virReportError(VIR_ERR_NO_DOMAIN,
> > +                               _("no domain with matching uuid '%s' (%s)"),
> > +                               uuidstr, dom->name);
> > +                virObjectUnlock(domlist);
> > +                goto error;
> > +            }
> > +        } else {
> > +            virObjectRef(vm);
> > +
> > +            if (VIR_APPEND_ELEMENT(*vms, *nvms, vm) < 0)
> > +                goto error;
> > +        }
> > +    }
> > +    virObjectUnlock(domlist);
> > +
> > +    virDomainObjListFilter(vms, nvms, conn, filter, flags);
> 
> Coverity complains here too - if 'vms' is NULL, then ObjListFilter
> derefs.  Coverity shows an example of ndoms == 2 and for each iteration
> through the loop it takes the skip_missing path.

False positive again. If every domain is skipped, then nvms will never
be incremented from it's 0 state where it was pre-set.

virDomainObjListFilter then iterates from 0 while it's less than the
value stored in ndoms ( which is 0) thus it never touches @vms.

Peter

Attachment: signature.asc
Description: Digital signature


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