From: Charles Giessen Date: Thu, 11 Jul 2024 17:13:18 +0000 (-0700) Subject: Fix RegCloseKey exeption when double-closing hKeys X-Git-Tag: upstream/1.3.296~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8e1076d9363787b4e754ac17e7ee6ab806458f7c;p=platform%2Fupstream%2FVulkan-Loader.git Fix RegCloseKey exeption when double-closing hKeys While the application still can run, RegCloseKey will throw an error when key is double-closed. This was caused by the test framework not catching when the double-close occurs. --- diff --git a/loader/loader_windows.c b/loader/loader_windows.c index 43ecf667..74a9d723 100644 --- a/loader/loader_windows.c +++ b/loader/loader_windows.c @@ -1215,41 +1215,37 @@ VkResult get_settings_path_if_exists_in_registry_key(const struct loader_instanc VkResult windows_get_loader_settings_file_path(const struct loader_instance *inst, char **out_path) { VkResult result = VK_SUCCESS; DWORD access_flags = KEY_QUERY_VALUE; + LONG rtn_value = 0; HKEY key = NULL; - *out_path = NULL; - // if we are running with admin privileges, only check HKEY_LOCAL_MACHINE. - // Otherwise check HKEY_CURRENT_USER, and if nothing is there, look in HKEY_LOCAL_MACHINE + // Search in HKEY_CURRENT_USER first if we are running without admin privileges + // Exit if a settings file was found. + // Otherwise check in HKEY_LOCAL_MACHINE. - if (is_high_integrity()) { - LONG rtn_value = RegOpenKeyEx(HKEY_LOCAL_MACHINE, VK_SETTINGS_INFO_REGISTRY_LOC, 0, access_flags, &key); - if (ERROR_SUCCESS != rtn_value) { - result = VK_ERROR_FEATURE_NOT_PRESENT; - goto out; - } - result = get_settings_path_if_exists_in_registry_key(inst, out_path, key); - } else { - LONG rtn_value = RegOpenKeyEx(HKEY_CURRENT_USER, VK_SETTINGS_INFO_REGISTRY_LOC, 0, access_flags, &key); + if (!is_high_integrity()) { + rtn_value = RegOpenKeyEx(HKEY_CURRENT_USER, VK_SETTINGS_INFO_REGISTRY_LOC, 0, access_flags, &key); if (ERROR_SUCCESS == rtn_value) { result = get_settings_path_if_exists_in_registry_key(inst, out_path, key); - RegCloseKey(key); + // Either we got OOM and *must* exit or we successfully found the settings file and can exit if (result == VK_ERROR_OUT_OF_HOST_MEMORY || result == VK_SUCCESS) { goto out; } + RegCloseKey(key); + key = NULL; } + } - rtn_value = RegOpenKeyEx(HKEY_LOCAL_MACHINE, VK_SETTINGS_INFO_REGISTRY_LOC, 0, access_flags, &key); - if (ERROR_SUCCESS != rtn_value) { - result = VK_ERROR_FEATURE_NOT_PRESENT; - goto out; - } + rtn_value = RegOpenKeyEx(HKEY_LOCAL_MACHINE, VK_SETTINGS_INFO_REGISTRY_LOC, 0, access_flags, &key); + if (ERROR_SUCCESS != rtn_value) { + result = VK_ERROR_FEATURE_NOT_PRESENT; + goto out; + } - result = get_settings_path_if_exists_in_registry_key(inst, out_path, key); - if (result == VK_ERROR_OUT_OF_HOST_MEMORY) { - goto out; - } + result = get_settings_path_if_exists_in_registry_key(inst, out_path, key); + if (result == VK_ERROR_OUT_OF_HOST_MEMORY) { + goto out; } out: diff --git a/tests/framework/shim/windows_shim.cpp b/tests/framework/shim/windows_shim.cpp index 6f59dc67..7c46046c 100644 --- a/tests/framework/shim/windows_shim.cpp +++ b/tests/framework/shim/windows_shim.cpp @@ -346,7 +346,8 @@ LSTATUS __stdcall ShimRegCloseKey(HKEY hKey) { return ERROR_SUCCESS; } } - return ERROR_SUCCESS; + // means that RegCloseKey was called with an invalid key value (one that doesn't exist or has already been closed) + exit(-1); } // Windows app package shims