Check for nullptr in vkCreateInstance trampoline
authorCharles Giessen <charles@lunarg.com>
Mon, 23 Oct 2023 23:30:37 +0000 (17:30 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Tue, 24 Oct 2023 15:04:58 +0000 (09:04 -0600)
pCreateInfo must not be NULL, but the loader was dereferencing the pointer
before checking if it is NULL. Moving the dereference below the check for
NULL ensures no nullptr dereferencing occurs.

loader/trampoline.c

index cd3160dcf7a817e5c0bc9f76e07e3ad828f3813d..bcc55bf42579581254948ebc4acad80e56ba7e28 100644 (file)
@@ -489,7 +489,7 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCr
     struct loader_instance *ptr_instance = NULL;
     VkInstance created_instance = VK_NULL_HANDLE;
     VkResult res = VK_ERROR_INITIALIZATION_FAILED;
-    VkInstanceCreateInfo ici = *pCreateInfo;
+    VkInstanceCreateInfo ici = {0};
     struct loader_envvar_all_filters layer_filters = {0};
 
     LOADER_PLATFORM_THREAD_ONCE(&once_init, loader_initialize);
@@ -499,6 +499,8 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCr
                    "vkCreateInstance: \'pCreateInfo\' is NULL (VUID-vkCreateInstance-pCreateInfo-parameter)");
         goto out;
     }
+    ici = *pCreateInfo;
+
     if (pInstance == NULL) {
         loader_log(NULL, VULKAN_LOADER_FATAL_ERROR_BIT | VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_VALIDATION_BIT, 0,
                    "vkCreateInstance \'pInstance\' not valid (VUID-vkCreateInstance-pInstance-parameter)");