diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index f14bb4b20cf41..328d1a9f50125 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -26,7 +26,7 @@ static bool check_overlaps(json_engine_t *, json_engine_t *, bool); static int json_find_overlap_with_object(json_engine_t *, json_engine_t *, bool); #ifndef DBUG_OFF -static int dbug_json_check_min_stack_requirement() +int dbug_json_check_min_stack_requirement() { my_error(ER_STACK_OVERRUN_NEED_MORE, MYF(ME_FATAL), my_thread_stack_size, my_thread_stack_size, STACK_MIN_SIZE); diff --git a/sql/json_schema.cc b/sql/json_schema.cc index c5dfdec409aec..dd5862acb1761 100644 --- a/sql/json_schema.cc +++ b/sql/json_schema.cc @@ -21,6 +21,11 @@ #include "json_schema.h" #include "json_schema_helper.h" #include "pcre2.h" + +#ifndef DBUG_OFF +int dbug_json_check_min_stack_requirement(); +#endif + static HASH all_keywords_hash; static Json_schema_keyword *create_json_schema_keyword(THD *thd) @@ -2779,15 +2784,9 @@ bool create_object_and_handle_keyword(THD *thd, json_engine_t *je, List temporary_list; DBUG_EXECUTE_IF("json_check_min_stack_requirement", - { - long arbitrary_var; - long stack_used_up= - (available_stack_size(thd->thread_stack, - &arbitrary_var)); - ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); - }); + dbug_json_check_min_stack_requirement(); return true;); if (check_stack_overrun(thd, STACK_MIN_SIZE , NULL)) - return 1; + return true; while (json_scan_next(je)== 0 && je->stack_p >= level) { diff --git a/sql/json_table.cc b/sql/json_table.cc index 0f1ec1156f0e2..5337c6d92f6a6 100644 --- a/sql/json_table.cc +++ b/sql/json_table.cc @@ -27,6 +27,10 @@ #include "create_tmp_table.h" #include "sql_parse.h" +#ifndef DBUG_OFF +int dbug_json_check_min_stack_requirement(); +#endif + #define HA_ERR_JSON_TABLE (HA_ERR_LAST+1) class table_function_handlerton @@ -104,13 +108,9 @@ int get_disallowed_table_deps_for_list(MEM_ROOT *mem_root, List_iterator li(*join_list); DBUG_EXECUTE_IF("json_check_min_stack_requirement", - { - long arbitrary_var; - long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); - ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); - }); + return -dbug_json_check_min_stack_requirement();); if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL)) - return 1; + return -1; while ((table= li++)) { @@ -1345,19 +1345,15 @@ void Table_function_json_table::fix_after_pullout(TABLE_LIST *sql_table, Recursively make all tables in the join_list also depend on deps. */ -static void add_extra_deps(List *join_list, table_map deps) +static bool add_extra_deps(List *join_list, table_map deps) { TABLE_LIST *table; List_iterator li(*join_list); DBUG_EXECUTE_IF("json_check_min_stack_requirement", - { - long arbitrary_var; - long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); - ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); - }); + dbug_json_check_min_stack_requirement(); return true;); if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL)) - return; + return true; while ((table= li++)) { table->dep_tables |= deps; @@ -1365,9 +1361,11 @@ static void add_extra_deps(List *join_list, table_map deps) if ((nested_join= table->nested_join)) { // set the deps inside, too - add_extra_deps(&nested_join->join_list, deps); + if (add_extra_deps(&nested_join->join_list, deps)) + return true; } } + return false; } @@ -1447,11 +1445,7 @@ table_map add_table_function_dependencies(List *join_list, List_iterator li(*join_list); DBUG_EXECUTE_IF("json_check_min_stack_requirement", - { - long arbitrary_var; - long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); - ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); - }); + if (dbug_json_check_min_stack_requirement()) return 0;); if ((res=check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL))) return res; diff --git a/sql/sql_parse.h b/sql/sql_parse.h index 94dc19094ca59..9d846d7d0e2ee 100644 --- a/sql/sql_parse.h +++ b/sql/sql_parse.h @@ -189,20 +189,4 @@ check_table_access(THD *thd, privilege_t requirements,TABLE_LIST *tables, { return false; } #endif /*NO_EMBEDDED_ACCESS_CHECKS*/ - -/* - Allocating memory and *also* using it (reading and - writing from it) because some build instructions cause - compiler to optimize out stack_used_up. Since alloca() - here depends on stack_used_up, it doesnt get executed - correctly and causes json_debug_nonembedded to fail - ( --error ER_STACK_OVERRUN_NEED_MORE does not occur). -*/ -#define ALLOCATE_MEM_ON_STACK(A) do \ - { \ - uchar *array= (uchar*)alloca(A); \ - bzero(array, A); \ - my_checksum(0, array, A); \ - } while(0) - #endif /* SQL_PARSE_INCLUDED */