diff --git a/mysql-test/main/json_debug_nonembedded.result b/mysql-test/main/json_debug_nonembedded.result new file mode 100644 index 00000000000..e759cafa38b --- /dev/null +++ b/mysql-test/main/json_debug_nonembedded.result @@ -0,0 +1,13 @@ +# +# MDEV-28762: recursive call of some json functions without stack control +# +SET @saved_dbug = @@debug_dbug; +SET debug_dbug='+d,json_check_min_stack_requirement'; +SET @json1= '{"key1":"val1"}'; +SET @json2= '{"key1":"val1"}'; +SELECT JSON_OVERLAPS(@json1, @json2); +ERROR HY000: Thread stack overrun: 'used bytes' used of a 'available' byte stack, and 'X' bytes needed. Consider increasing the thread_stack system variable. +SET @@debug_dbug= @saved_dbug; +# +# End of 10.9 test +# diff --git a/mysql-test/main/json_debug_nonembedded.test b/mysql-test/main/json_debug_nonembedded.test new file mode 100644 index 00000000000..5813b46e556 --- /dev/null +++ b/mysql-test/main/json_debug_nonembedded.test @@ -0,0 +1,22 @@ +-- source include/not_embedded.inc +--source include/have_debug.inc + +--echo # +--echo # MDEV-28762: recursive call of some json functions without stack control +--echo # + +SET @saved_dbug = @@debug_dbug; +SET debug_dbug='+d,json_check_min_stack_requirement'; + +SET @json1= '{"key1":"val1"}'; +SET @json2= '{"key1":"val1"}'; + +--replace_regex /overrun: [0-9]* bytes used of a [0-9]* byte stack, and [0-9]* bytes needed/overrun: 'used bytes' used of a 'available' byte stack, and 'X' bytes needed/ +--error ER_STACK_OVERRUN_NEED_MORE +SELECT JSON_OVERLAPS(@json1, @json2); + +SET @@debug_dbug= @saved_dbug; + +--echo # +--echo # End of 10.9 test +--echo # diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index acf5c199a02..da8478a5f27 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -18,6 +18,7 @@ #include "sql_priv.h" #include "sql_class.h" #include "item.h" +#include "sql_parse.h" /* @@ -4406,6 +4407,11 @@ int json_find_overlap_with_object(json_engine_t *js, json_engine_t *value, */ int check_overlaps(json_engine_t *js, json_engine_t *value, bool compare_whole) { + DBUG_EXECUTE_IF("json_check_min_stack_requirement", + {alloca(my_thread_stack_size-(STACK_MIN_SIZE));}); + if (check_stack_overrun(current_thd, STACK_MIN_SIZE, NULL)) + return 0; + switch (js->value_type) { case JSON_VALUE_OBJECT: