From 0fa23840d35ec07ac182be6effe8d3eff5cb2d9f Mon Sep 17 00:00:00 2001 From: Piers Daniell Date: Fri, 3 Jun 2022 12:21:00 -0600 Subject: [PATCH] Fix regression from CL-9387 to handle empty cache properly The new program cache code from CL-9387 didn't handle the case where cacheSearch() is called with an empty cache. It would look at the first node key regardless, which is uninitialized data, and attempt to follow the left/right node pointers, which were also uninitialized. This could result in crash or worse. This CL simply checks if the cache is empty, and if so doesn't attempt to read the invalid first node. Affects: * (all tests with shaders) VK-GL-CTS issue: 3565 Components: Vulkan, Framework Change-Id: Ia813d8caf3170b0c1995bdc43a5f345b578ab615 --- external/vulkancts/framework/vulkan/vkPrograms.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/external/vulkancts/framework/vulkan/vkPrograms.cpp b/external/vulkancts/framework/vulkan/vkPrograms.cpp index 2b06e79..1653ded 100644 --- a/external/vulkancts/framework/vulkan/vkPrograms.cpp +++ b/external/vulkancts/framework/vulkan/vkPrograms.cpp @@ -234,8 +234,14 @@ struct cacheNode cacheNode* cacheSearch (deUint32 key) { - cacheNode* r = (cacheNode*)(cacheMempool + 1); - unsigned int p = 0; + cacheNode* r = (cacheNode*)(cacheMempool + 1); + int* tail = (int*)cacheMempool; + unsigned int p = 0; + + if (!*tail) { + // Cache is empty. + return 0; + } while (1) { -- 2.7.4