1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

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
This commit is contained in:
Daniel Black
2026-10-01 13:50:32 +10:00
parent f59e460200
commit f7e7c6bea4
3 changed files with 22 additions and 7 deletions

View File

@@ -6217,4 +6217,10 @@ SET @value= '
SELECT JSON_SCHEMA_VALID(@schema, @value);
JSON_SCHEMA_VALID(@schema, @value)
1
#
# MDEV-41156 ASAN use-after-poison in json_skip_array_and_count/Item_func_json_contains_path::val_bool
#
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;
r
1
# End of 12.3 tests

View File

@@ -4766,4 +4766,10 @@ SET @value= '
SELECT JSON_SCHEMA_VALID(@schema, @value);
--echo #
--echo # MDEV-41156 ASAN use-after-poison in json_skip_array_and_count/Item_func_json_contains_path::val_bool
--echo #
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;
--echo # End of 12.3 tests

View File

@@ -2082,15 +2082,18 @@ bool Item_func_json_contains_path::val_bool()
result= 0;
while (json_get_path_next(&je, &p) == 0)
{
int n_path= arg_count - 2, value= 0, *value_ptr= NULL;
int n_path= arg_count - 2;
value_ptr= (int*)(json_depth_array.buffer)+(p.last_step_idx);
int *value_ptr=
(int *)mem_root_dynamic_array_resize_and_get_val(&json_depth_array,
p.last_step_idx);
if (!value_ptr)
{
je.s.error= JE_EOS;
break;
}
if (has_negative_path && je.value_type == JSON_VALUE_ARRAY &&
(json_skip_array_and_count(&je,
value_ptr ? value_ptr : &value) ||
mem_root_dynamic_array_resize_and_set_val(&json_depth_array,
value_ptr ? value_ptr : &value,
p.last_step_idx)))
json_skip_array_and_count(&je, value_ptr))
{
result= 1;
break;