From 042720a89b410c2348a30bac14ca56cb9694b99e Mon Sep 17 00:00:00 2001 From: Jon Ashburn Date: Tue, 14 Apr 2015 09:15:32 -0600 Subject: [PATCH] loader: Add check for invalid enabled extensions at CreateInstance --- loader/loader.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/loader/loader.c b/loader/loader.c index 712118a..e9f51ca 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -351,6 +351,17 @@ static void loader_add_to_ext_list(uint32_t count, } } +static bool loader_is_extension_scanned(const char *name) +{ + uint32_t i; + + for (i = 0; i < loader.scanned_ext_list_count; i++) { + if (!strcmp(name, loader.scanned_ext_list[i]->extName)) + return true; + } + return false; +} + static void loader_coalesce_extensions() { uint32_t i; @@ -1075,8 +1086,12 @@ LOADER_EXPORT VkResult VKAPI vkCreateInstance( ptr_instance->extension_count = pCreateInfo->extensionCount; ptr_instance->extension_names = (ptr_instance->extension_count > 0) ? malloc(sizeof (char *) * ptr_instance->extension_count) : NULL; + if (ptr_instance->extension_names == NULL && (ptr_instance->extension_count > 0)) + return VK_ERROR_OUT_OF_MEMORY; for (i = 0; i < ptr_instance->extension_count; i++) { - ptr_instance->extension_names[i] = malloc(strlen(pCreateInfo->ppEnabledExtensionNames[i] + 1)); + if (!loader_is_extension_scanned(pCreateInfo->ppEnabledExtensionNames[i])) + return VK_ERROR_INVALID_EXTENSION; + ptr_instance->extension_names[i] = malloc(strlen(pCreateInfo->ppEnabledExtensionNames[i]) + 1); if (ptr_instance->extension_names[i] == NULL) return VK_ERROR_OUT_OF_MEMORY; strcpy(ptr_instance->extension_names[i], pCreateInfo->ppEnabledExtensionNames[i]); -- 2.7.4