Skip to content

Commit f7e7c6b

Browse files
committed
MDEV-41156: ASAN use-after-poison in JSON_CONTAINS_PATH
The json_depth_array as allocated for 32 elements but accessed it as though there wasn't a limit. Called mem_root_dynamic_array_resize_and_get_val to ensure that the number of elements was presented, and error JE_EOS (out of space) if allocation exceeded and return its pointer. With the array resizing called early mem_root_dynamic_array_resize_and_set_val isn't required. Removed unused 'value' variable, as value_ptr was always valid. Reported by: David Korczynski of Ada Logics
1 parent f59e460 commit f7e7c6b

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

‎mysql-test/main/func_json.result‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6217,4 +6217,10 @@ SET @value= '
62176217
SELECT JSON_SCHEMA_VALID(@schema, @value);
62186218
JSON_SCHEMA_VALID(@schema, @value)
62196219
1
6220+
#
6221+
# MDEV-41156 ASAN use-after-poison in json_skip_array_and_count/Item_func_json_contains_path::val_bool
6222+
#
6223+
SELECT JSON_CONTAINS_PATH('[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,2,3]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]', 'one', '$[last]') AS r;
6224+
r
6225+
1
62206226
# End of 12.3 tests

‎mysql-test/main/func_json.test‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4766,4 +4766,10 @@ SET @value= '
47664766

47674767
SELECT JSON_SCHEMA_VALID(@schema, @value);
47684768

4769+
--echo #
4770+
--echo # MDEV-41156 ASAN use-after-poison in json_skip_array_and_count/Item_func_json_contains_path::val_bool
4771+
--echo #
4772+
4773+
SELECT JSON_CONTAINS_PATH('[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,1,1,1,1,1,[1,2,3]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]', 'one', '$[last]') AS r;
4774+
47694775
--echo # End of 12.3 tests

‎sql/item_jsonfunc.cc‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,15 +2082,18 @@ bool Item_func_json_contains_path::val_bool()
20822082
result= 0;
20832083
while (json_get_path_next(&je, &p) == 0)
20842084
{
2085-
int n_path= arg_count - 2, value= 0, *value_ptr= NULL;
2085+
int n_path= arg_count - 2;
20862086

2087-
value_ptr= (int*)(json_depth_array.buffer)+(p.last_step_idx);
2087+
int *value_ptr=
2088+
(int *)mem_root_dynamic_array_resize_and_get_val(&json_depth_array,
2089+
p.last_step_idx);
2090+
if (!value_ptr)
2091+
{
2092+
je.s.error= JE_EOS;
2093+
break;
2094+
}
20882095
if (has_negative_path && je.value_type == JSON_VALUE_ARRAY &&
2089-
(json_skip_array_and_count(&je,
2090-
value_ptr ? value_ptr : &value) ||
2091-
mem_root_dynamic_array_resize_and_set_val(&json_depth_array,
2092-
value_ptr ? value_ptr : &value,
2093-
p.last_step_idx)))
2096+
json_skip_array_and_count(&je, value_ptr))
20942097
{
20952098
result= 1;
20962099
break;

0 commit comments

Comments
 (0)