From 44f3dd08f99ba67e967980daaea2b800c68e2659 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Wed, 24 Oct 2018 10:11:49 +0200 Subject: 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 --- src/linux_sysfs.c | 1 + 1 file changed, 1 insertion(+) 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; -- cgit v1.2.1