diff options
author | Olivier Fourdan <ofourdan@redhat.com> | 2018-10-24 10:11:49 +0200 |
---|---|---|
committer | Olivier Fourdan <ofourdan@redhat.com> | 2018-10-24 10:22:25 +0200 |
commit | 44f3dd08f99ba67e967980daaea2b800c68e2659 (patch) | |
tree | 52e2cca9844787da1d9a7444544fc44bd6218c6a | |
parent | 13854f603f720c45caf51d785a874d3c7e8c5f58 (diff) |
linux: Set number of devices to 0 in case of error
pci_sys is a global variable which is populated on init, and in case of
error reading sysfs on Linux, the devices are NULL, but the number of
devices is left unchanged.
As a result, we may crash in `pci_device_next()` which relies on the
number of devices.
To fix the issue, simply reset the number of devices to zero in case of
error so we don't try to access indices of a NULL array later on.
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
-rw-r--r-- | src/linux_sysfs.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/linux_sysfs.c b/src/linux_sysfs.c index a8bc2e1..e74ad72 100644 --- a/src/linux_sysfs.c +++ b/src/linux_sysfs.c @@ -264,6 +264,7 @@ populate_entries( struct pci_system * p ) if (err) { free(p->devices); p->devices = NULL; + p->num_devices = 0; } return err; |