[libvirt] [PATCH] pci: Give an explicit error if device not found

Eric Blake eblake at redhat.com
Tue May 4 21:07:12 UTC 2010


On 04/30/2010 09:44 AM, Cole Robinson wrote:
> @@ -1028,6 +1028,7 @@ pciGetDevice(unsigned domain,
>               unsigned function)
>  {
>      pciDevice *dev;
> +    char devdir[PATH_MAX];

Using PATH_MAX as an array size is dangerous; it fails on GNU Hurd where
there is no minimum size.  Also, it wastes a lot of space, given your
usage...

>      char *vendor, *product;
>  
>      if (VIR_ALLOC(dev) < 0) {
> @@ -1043,8 +1044,17 @@ pciGetDevice(unsigned domain,
>  
>      snprintf(dev->name, sizeof(dev->name), "%.4x:%.2x:%.2x.%.1x",
>               dev->domain, dev->bus, dev->slot, dev->function);
> +    snprintf(devdir, sizeof(devdir),
> +             PCI_SYSFS "devices/%s", dev->name);

...here, of concatenating two relatively short strings.  I'd almost
rather see a virAsprintf/free.

>      snprintf(dev->path, sizeof(dev->path),
> -             PCI_SYSFS "devices/%s/config", dev->name);
> +             "%s/%s/config", devdir, dev->name);
> +
> +    if (access(devdir, X_OK) != 0) {

Is this ever run in a situation where the effective id might not equal
the user id (that is, as a setuid script, or as root)?  If so, would it
be better to use faccessat(...,AT_EACCESS) instead of access() to be
querying the correct permissions?  (Gnulib provides faccessat for all
platforms).

-- 
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/20100504/e87944fa/attachment-0001.sig>


More information about the libvir-list mailing list