diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index 540e47fefbd..5d5bf5bf8b0 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -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 diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test index bdcd22c0a9f..c5d95c86011 100644 --- a/mysql-test/main/func_json.test +++ b/mysql-test/main/func_json.test @@ -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 diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 89ab7c468c6..9ad628ee691 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -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;