diff options
author | Pali Rohár <pali@kernel.org> | 2022-11-18 23:40:39 +0100 |
---|---|---|
committer | Pali Rohár <pali@kernel.org> | 2022-11-18 23:40:39 +0100 |
commit | 64d7bab6f27418199d244481664255b24c7ffc20 (patch) | |
tree | b73faf65e3e8bebdd8a8e411d43a3972d56387ee | |
parent | 6cf9052e88e23902a6fd1e6dcb8f07145383501c (diff) | |
download | pciutils-64d7bab6f27418199d244481664255b24c7ffc20.tar.gz |
libpci: windows: Handle long paths generated by GetModuleFileName()
C function fopen() implemented by msvcrt.dll requires special prefix
"\\\\?\\" for paths longer than 260 bytes. Because GetModuleFileName()
returns absolute path, it may be longer than 260 bytes. Add fixup to handle
long paths.
-rw-r--r-- | lib/init.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -336,9 +336,16 @@ retry: * directory, hence something completely different. So prepend missing * "\\\\?\\" prefix to make path valid again. * Reproduce: CreateProcessW("\\??\\UNC\\10.0.2.4\\qemu\\lspci.exe", ...) + * + * If path starts with DOS drive letter and with appended PCI_IDS is + * longer than 260 bytes and is without "\\\\?\\" prefix then append it. + * This prefix is required for paths and file names with DOS drive letter + * longer than 260 bytes. */ if (strncmp(path, "\\UNC\\", 5) == 0 || - strncmp(path, "UNC\\", 4) == 0) + strncmp(path, "UNC\\", 4) == 0 || + (((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z')) && + len + sizeof(PCI_IDS) >= 260)) { memmove(path+4, path, len); memcpy(path, "\\\\?\\", 4); |