From 03f8772aa6da74d38dde1ef3737491e2e214b619 Mon Sep 17 00:00:00 2001 From: Martin Blanchard Date: Wed, 9 May 2018 22:47:12 +0100 Subject: loader: Remove duplicated delimiting chars in paths Before loading a manifest file, its full path is strcmp() with already loaded ones in order not to load the same file twice. While being simple and efficent, this mechanism is not able to detect subtle duplicates like these: /usr/share/vulkan/icd.d/intel_icd.x86_64.json /usr/share//vulkan/icd.d/intel_icd.x86_64.json This patch ensure that searched paths do not contains such duplicated directory delimiting characters in order to avoid this kind of problem. Fixes #2331 Fixes #2629 --- loader/loader.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'loader/loader.c') diff --git a/loader/loader.c b/loader/loader.c index 7298c672..26ff5200 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -3029,6 +3029,7 @@ static VkResult loader_get_manifest_files(const struct loader_instance *inst, co const char *override = NULL; char *override_getenv = NULL; char *loc, *orig_loc = NULL; + size_t loc_size = 0; char *reg = NULL; char *file, *next_file, *name; size_t alloced_count = 64; @@ -3076,7 +3077,6 @@ static VkResult loader_get_manifest_files(const struct loader_instance *inst, co // Make a copy of the input we are using so it is not modified // Also handle getting the location(s) from registry on Windows if (override == NULL) { - size_t loc_size = 0; #if !defined(_WIN32) const char *xdgconfdirs = loader_secure_getenv("XDG_CONFIG_DIRS", inst); const char *xdgdatadirs = loader_secure_getenv("XDG_DATA_DIRS", inst); @@ -3257,6 +3257,18 @@ static VkResult loader_get_manifest_files(const struct loader_instance *inst, co strcpy(loc, override); } + size_t n = 0; + loc_size = strlen(loc); + // Remove duplicated directory symbols (could hide duplicated paths) + for (size_t i = 0; i < loc_size; i++) { + if (n > 0) loc[i] = loc[i + n]; + if (loc[i] == DIRECTORY_SYMBOL && loc[i + 1 + n] == DIRECTORY_SYMBOL) { + loc_size--; + n++; + } + } + loc[loc_size] = '\0'; + // Print out the paths being searched if debugging is enabled loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, "Searching the following paths for manifest files: %s\n", loc); -- cgit v1.2.3