diff options
author | Roman Kiryanov <rkir@google.com> | 2019-04-24 17:51:13 -0700 |
---|---|---|
committer | Roman Kiryanov <rkir@google.com> | 2019-04-26 16:50:36 -0700 |
commit | 9a5220d9ee3eeff520c5e67bd36584612a890579 (patch) | |
tree | bd45e02483aa324bcdd002a5cbe9eea576831cec | |
parent | 872613d9c5b00b93db0eea1c64765ee1d5c1480e (diff) | |
download | device_generic_goldfish-opengl-9a5220d9ee3eeff520c5e67bd36584612a890579.tar.gz device_generic_goldfish-opengl-9a5220d9ee3eeff520c5e67bd36584612a890579.tar.bz2 device_generic_goldfish-opengl-9a5220d9ee3eeff520c5e67bd36584612a890579.zip |
Fix vk_append_struct to add elements after the last one
This also limits list's length to some random number
to crash if the struct chain has a loop.
Bug: 131181334
Test: make
Change-Id: I385dc02012290b2e1a2a07dd00e209326a7196b5
Merged-In: I4e7beb622afc35ee26b58f7060596bd3f2250156
Signed-off-by: Roman Kiryanov <rkir@google.com>
-rw-r--r-- | system/vulkan_enc/vk_util.h | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/system/vulkan_enc/vk_util.h b/system/vulkan_enc/vk_util.h index 0c7f4b98..a60d3d88 100644 --- a/system/vulkan_enc/vk_util.h +++ b/system/vulkan_enc/vk_util.h @@ -215,11 +215,28 @@ vk_init_struct_chain(vk_struct_common* start) } static inline vk_struct_common* +vk_last_struct_chain(vk_struct_common* i) +{ + for (int n = 1000000; n > 0; --n) { + vk_struct_common* next = i->pNext; + if (next) { + i = next; + } else { + return i; + } + } + + ::abort(); // crash on loops in the chain + return NULL; +} + +static inline vk_struct_common* vk_append_struct(vk_struct_common* current, vk_struct_common* next) { - current->pNext = next; - next->pNext = nullptr; - return next; + vk_struct_common* last = vk_last_struct_chain(current); + last->pNext = next; + next->pNext = nullptr; + return current; } #endif /* VK_UTIL_H */ |