mirror of
https://github.com/MariaDB/server.git
synced 2025-08-31 22:22:30 +03:00
BUG#21856: Prepared Statements: crash if bad create
When statement to be prepared contained CREATE PROCEDURE, CREATE FUNCTION or CREATE TRIGGER statements with a syntax error in it, the preparation would fail with syntax error message, but the memory could be corrupted. The problem occurred because we switch memroot when parse stored routine or trigger definitions, and on parse error we restored the original memroot only after performing some memory operations. In more detail: - prepared statement would activate its own memory root to parse the definition of the stored procedure. - SP would reset this memory root with its own memory root to parse SP statements - a syntax error would happen - prepared statement would restore the original memory root - stored procedure would restore what it thinks was the original memory root, but actually was the statement memory root. That led to double free - in destruction of the statement and in a next call to mysql_parse(). The solution is to restore memroot right after the failed parsing.
This commit is contained in:
@@ -5852,14 +5852,19 @@ void mysql_parse(THD *thd, char *inBuf, uint length)
|
||||
DBUG_ASSERT(thd->net.report_error);
|
||||
DBUG_PRINT("info",("Command aborted. Fatal_error: %d",
|
||||
thd->is_fatal_error));
|
||||
query_cache_abort(&thd->net);
|
||||
lex->unit.cleanup();
|
||||
|
||||
/*
|
||||
The first thing we do after parse error is freeing sp_head to
|
||||
ensure that we have restored original memroot.
|
||||
*/
|
||||
if (thd->lex->sphead)
|
||||
{
|
||||
/* Clean up after failed stored procedure/function */
|
||||
delete thd->lex->sphead;
|
||||
thd->lex->sphead= NULL;
|
||||
}
|
||||
query_cache_abort(&thd->net);
|
||||
lex->unit.cleanup();
|
||||
}
|
||||
thd->proc_info="freeing items";
|
||||
thd->end_statement();
|
||||
|
Reference in New Issue
Block a user