From 5f93596f916038bdb611ca5af351e849f9c02d39 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pali=20Roh=C3=A1r?= Date: Sun, 27 Feb 2022 01:57:38 +0100 Subject: [PATCH] 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). --- lib/init.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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)); -- 2.39.5