diff --git a/mysql-test/main/thread_stack_overrun.opt b/mysql-test/main/thread_stack_overrun.opt new file mode 100644 index 0000000000000..d3e1e3fd51ab2 --- /dev/null +++ b/mysql-test/main/thread_stack_overrun.opt @@ -0,0 +1 @@ +--thread-stack=256K diff --git a/mysql-test/main/thread_stack_overrun.result b/mysql-test/main/thread_stack_overrun.result new file mode 100644 index 0000000000000..56d599da33d40 --- /dev/null +++ b/mysql-test/main/thread_stack_overrun.result @@ -0,0 +1,5 @@ +# +# MDEV-37781 ASAN build crashes with low thread stack +# +EXECUTE IMMEDIATE CONCAT('SELECT 1', REPEAT('+1', @@global.thread_stack)); +ERROR HY000: Thread stack overrun: # bytes used of a # byte stack, and # bytes needed. Consider increasing the thread_stack system variable. diff --git a/mysql-test/main/thread_stack_overrun.test b/mysql-test/main/thread_stack_overrun.test new file mode 100644 index 0000000000000..76682028cf511 --- /dev/null +++ b/mysql-test/main/thread_stack_overrun.test @@ -0,0 +1,15 @@ +--echo # +--echo # MDEV-37781 ASAN build crashes with low thread stack +--echo # + +--source include/not_embedded.inc + +# Expression like 1+1+...+1 recurses once per term in fix_fields(). +# As each recursion level consumes at least one byte of stack, we use +# @@global.thread_stack terms to have a guaranteed stack overrun +# on any platform, no matter the frame size. + +--replace_regex /[0-9]+ bytes used of a [0-9]+ byte stack, and [0-9]+ bytes needed/# bytes used of a # byte stack, and # bytes needed/ + +--error ER_STACK_OVERRUN_NEED_MORE +EXECUTE IMMEDIATE CONCAT('SELECT 1', REPEAT('+1', @@global.thread_stack)); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index ab563a54e2df5..8e5c488977be3 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7636,7 +7636,6 @@ __attribute__((optimize("-O0"))) #endif check_stack_overrun(THD *thd, long margin, uchar *buf __attribute__((unused))) { -#ifndef __SANITIZE_ADDRESS__ long stack_used; DBUG_ASSERT(thd == current_thd); DBUG_ASSERT(thd->thread_stack); @@ -7661,7 +7660,6 @@ check_stack_overrun(THD *thd, long margin, uchar *buf __attribute__((unused))) #ifndef DBUG_OFF max_stack_used= MY_MAX(max_stack_used, stack_used); #endif -#endif /* __SANITIZE_ADDRESS__ */ return 0; }