From 54ca3aa25f5dd551d974724524b5f0958da35b34 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 20 May 2021 19:49:23 +0200 Subject: types: fix uninitialized memory on setting non-contiguous array indexes When ucode sets array indexes far after the array end so that a realloc() is triggered interally, the memory between the last existing array element and the newly set one was left uninitialized, leading to random segmentation faults, infinite loops or other invalid memory access symptoms. Signed-off-by: Jo-Philipp Wich --- types.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types.c b/types.c index af56320..b1172eb 100644 --- a/types.c +++ b/types.c @@ -699,13 +699,18 @@ bool ucv_array_set(uc_value_t *uv, size_t index, uc_value_t *item) { uc_array_t *array = (uc_array_t *)uv; + size_t old_count; if (ucv_type(uv) != UC_ARRAY) return false; if (index >= array->count) { + old_count = array->count; array->count = index + 1; uc_vector_grow(array); + + while (old_count < array->count) + array->entries[old_count++] = NULL; } else { ucv_put(array->entries[index]); -- cgit v1.2.3