diff options
author | Jo-Philipp Wich <jo@mein.io> | 2024-10-16 11:43:31 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2024-10-17 09:15:21 +0200 |
commit | 736d4508420222321468feedd60e7cb5063b574d (patch) | |
tree | 8d4680166f8bfc5202165ac9bc08677590e2a2b1 /tests/custom/99_bugs | |
parent | 9cf53dda36bc25b513ec1b1cdfc851a10b37473f (diff) |
types: fix potential use after free on adding keys during iteration
When keys are added to the object currently being iterated by a for loop,
the insert operation might cause a hashtable resize with a subsequent
memory reallocation and a different table base pointer, clobbering the
entry pointers held by iterators pointing to the containing object of the
resized table.
In order to address this issue while keeping the iteration overhead low,
extend the object key insert logic to check whether the insertion will
trigger a reallocation and backup and restore the iterator pointers when
needed.
This slightly increases the size of the iterator states but the overhead
for this should be neglectible as there'll only be a low amount of
concurrently active iterations at any time.
Fixes: #230
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/99_bugs')
-rw-r--r-- | tests/custom/99_bugs/48_use_after_free_on_iteration_insert | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/custom/99_bugs/48_use_after_free_on_iteration_insert b/tests/custom/99_bugs/48_use_after_free_on_iteration_insert new file mode 100644 index 0000000..558f83a --- /dev/null +++ b/tests/custom/99_bugs/48_use_after_free_on_iteration_insert @@ -0,0 +1,40 @@ +Ensure that adding keys to an object currently being iterated will not +clobber active iterators pointing into that object due to a reallocation +of the underlying hash table array. + +-- Testcase -- +{% + let obj = { '0': 0, '1': 1 }; + let i = 2; + + for (let k, v in obj) { + while (i < 16) { + obj[i] = i; + i++; + } + } + + printf("%.J\n", obj); +%} +-- End -- + +-- Expect stdout -- +{ + "0": 0, + "1": 1, + "2": 2, + "3": 3, + "4": 4, + "5": 5, + "6": 6, + "7": 7, + "8": 8, + "9": 9, + "10": 10, + "11": 11, + "12": 12, + "13": 13, + "14": 14, + "15": 15 +} +-- End -- |