From d80f2f8b8c29f9c96f2ab3a54f0420e96bb83dcd Mon Sep 17 00:00:00 2001 From: Mark Young Date: Mon, 26 Jun 2017 14:03:08 -0600 Subject: loader: Fix handling of JSON If a JSON layer manifest file says it contained device extensions but didn't provide a list, or the list was malformed, it caused issues. Change-Id: I94b97b190aca35f9464918eb7195486566becaa0 --- loader/loader.c | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'loader') diff --git a/loader/loader.c b/loader/loader.c index de57f5f0..05183b3f 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -912,33 +912,37 @@ VkResult loader_add_to_dev_ext_list(const struct loader_instance *inst, struct l memcpy(&ext_list->list[idx].props, props, sizeof(*props)); ext_list->list[idx].entrypoint_count = entry_count; - ext_list->list[idx].entrypoints = - loader_instance_heap_alloc(inst, sizeof(char *) * entry_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - if (ext_list->list[idx].entrypoints == NULL) { - loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, - "loader_add_to_dev_ext_list: Failed to allocate space " - "for device extension entrypoint list in list %d", - idx); - ext_list->list[idx].entrypoint_count = 0; - return VK_ERROR_OUT_OF_HOST_MEMORY; - } - for (uint32_t i = 0; i < entry_count; i++) { - ext_list->list[idx].entrypoints[i] = - loader_instance_heap_alloc(inst, strlen(entrys[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); - if (ext_list->list[idx].entrypoints[i] == NULL) { - for (uint32_t j = 0; j < i; j++) { - loader_instance_heap_free(inst, ext_list->list[idx].entrypoints[j]); - } - loader_instance_heap_free(inst, ext_list->list[idx].entrypoints); - ext_list->list[idx].entrypoint_count = 0; - ext_list->list[idx].entrypoints = NULL; + if (entry_count == 0) { + ext_list->list[idx].entrypoints = NULL; + } else { + ext_list->list[idx].entrypoints = + loader_instance_heap_alloc(inst, sizeof(char *) * entry_count, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + if (ext_list->list[idx].entrypoints == NULL) { loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, "loader_add_to_dev_ext_list: Failed to allocate space " - "for device extension entrypoint %d name", - i); + "for device extension entrypoint list in list %d", + idx); + ext_list->list[idx].entrypoint_count = 0; return VK_ERROR_OUT_OF_HOST_MEMORY; } - strcpy(ext_list->list[idx].entrypoints[i], entrys[i]); + for (uint32_t i = 0; i < entry_count; i++) { + ext_list->list[idx].entrypoints[i] = + loader_instance_heap_alloc(inst, strlen(entrys[i]) + 1, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE); + if (ext_list->list[idx].entrypoints[i] == NULL) { + for (uint32_t j = 0; j < i; j++) { + loader_instance_heap_free(inst, ext_list->list[idx].entrypoints[j]); + } + loader_instance_heap_free(inst, ext_list->list[idx].entrypoints); + ext_list->list[idx].entrypoint_count = 0; + ext_list->list[idx].entrypoints = NULL; + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, + "loader_add_to_dev_ext_list: Failed to allocate space " + "for device extension entrypoint %d name", + i); + return VK_ERROR_OUT_OF_HOST_MEMORY; + } + strcpy(ext_list->list[idx].entrypoints[i], entrys[i]); + } } ext_list->count++; -- cgit v1.2.3