aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2022-02-27 01:57:38 +0100
committerMartin Mareš <mj@ucw.cz>2022-04-15 23:57:52 +0200
commit5f93596f916038bdb611ca5af351e849f9c02d39 (patch)
treea3863ed262eab3337f99f754a36c6fcd62f6a02b
parentdc687532cd7c93dbeeb44ad857ac9aa936d74064 (diff)
downloadpciutils-5f93596f916038bdb611ca5af351e849f9c02d39.tar.gz
libpci: Always call pci_set_name_list_path() in pci_init_name_list_path()
If pci_init_name_list_path() does not call pci_set_name_list_path() then a->id_file_name variable is NULL and pci_load_name_list() would crash as it tries to do fopen(NULL, ...). If libpci was configured at compile time to use current executable path for locating pci.ids file and it is not possible to determinate current executable path then call pci_set_name_list_path() with just filename without path (this would fallback to the current working directory).
-rw-r--r--lib/init.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/init.c b/lib/init.c
index 463ae84..f997b2b 100644
--- a/lib/init.c
+++ b/lib/init.c
@@ -208,7 +208,10 @@ pci_init_name_list_path(struct pci_access *a)
len = GetModuleFileNameA(NULL, path, MAX_PATH+1);
sep = (len > 0) ? strrchr(path, '\\') : NULL;
if (len == 0 || len == MAX_PATH+1 || !sep || MAX_PATH-(size_t)(sep+1-path) < sizeof(PCI_IDS))
- free(path);
+ {
+ free(path);
+ pci_set_name_list_path(a, PCI_IDS, 0);
+ }
else
{
memcpy(sep+1, PCI_IDS, sizeof(PCI_IDS));