From: Charles Giessen Date: Mon, 17 May 2021 22:09:27 +0000 (-0600) Subject: loader: Prevent stack_alloc of 0 X-Git-Tag: upstream/v1.3.207~219 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9d080205692517218b452598511c887d48a3275d;p=platform%2Fupstream%2FVulkan-Loader.git loader: Prevent stack_alloc of 0 `loader_create_device_chain` would previously attempt to use stack allocations when `expanded_activated_layer_list.count` was zero, which is undefined behavior Change-Id: I56fab835a1728914191f1a7adc210dae58afa155 --- diff --git a/loader/loader.c b/loader/loader.c index 89adc8eb..acd3f923 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -4991,21 +4991,21 @@ VkResult loader_create_device_chain(const VkPhysicalDevice pd, const VkDeviceCre pNext = pNext->pNext; } } + if (dev->expanded_activated_layer_list.count > 0) { + layer_device_link_info = loader_stack_alloc(sizeof(VkLayerDeviceLink) * dev->expanded_activated_layer_list.count); + if (!layer_device_link_info) { + loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, + "loader_create_device_chain: Failed to alloc Device objects for layer. Skipping Layer."); + return VK_ERROR_OUT_OF_HOST_MEMORY; + } - layer_device_link_info = loader_stack_alloc(sizeof(VkLayerDeviceLink) * dev->expanded_activated_layer_list.count); - if (!layer_device_link_info) { - loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, - "loader_create_device_chain: Failed to alloc Device objects for layer. Skipping Layer."); - return VK_ERROR_OUT_OF_HOST_MEMORY; - } - - activated_layer_names = loader_stack_alloc(sizeof(char *) * inst->expanded_activated_layer_list.count); - if (!activated_layer_names) { - loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_create_instance_chain: Failed to alloc activated layer names array"); - return VK_ERROR_OUT_OF_HOST_MEMORY; - } + activated_layer_names = loader_stack_alloc(sizeof(char *) * inst->expanded_activated_layer_list.count); + if (!activated_layer_names) { + loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, + "loader_create_instance_chain: Failed to alloc activated layer names array"); + return VK_ERROR_OUT_OF_HOST_MEMORY; + } - if (dev->expanded_activated_layer_list.count > 0) { chain_info.sType = VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO; chain_info.function = VK_LAYER_LINK_INFO; chain_info.u.pLayerInfo = NULL;