]> mj.ucw.cz Git - pciutils.git/commitdiff
libpci: Always call pci_set_name_list_path() in pci_init_name_list_path()
authorPali Rohár <pali@kernel.org>
Sun, 27 Feb 2022 00:57:38 +0000 (01:57 +0100)
committerMartin Mareš <mj@ucw.cz>
Fri, 15 Apr 2022 21:57:52 +0000 (23:57 +0200)
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

index 463ae840b83f737bd123fbf6aad47aa481dbe146..f997b2bd83db39396c961bf0f01442aa9e52067c 100644 (file)
@@ -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));