Commit ea70b6a2 authored by Konstantin Osipov's avatar Konstantin Osipov

A fix for Bug#49972 "Crash in prepared statements":

The problem is introduced by WL#4435 "Support OUT-parameters in 
prepared statements".
When a statement that has out parameters was reprepared,
the reprepare request error was ignored, and an
attempt to send out parameters to the client was made.

Since the out parameter list was not initialized in case
of an error, this attempt led to a crash.

Don't try to send out parameters to the client
if an error occurred in statement execution.

sql/sql_prepare.cc:
  Don't try to send out parameters if error.
tests/mysql_client_test.c:
  Re-enable the test case for Bug#49972.
parent baab8dd8
...@@ -3769,7 +3769,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) ...@@ -3769,7 +3769,7 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
if (state == Query_arena::PREPARED) if (state == Query_arena::PREPARED)
state= Query_arena::EXECUTED; state= Query_arena::EXECUTED;
if (this->lex->sql_command == SQLCOM_CALL) if (error == 0 && this->lex->sql_command == SQLCOM_CALL)
{ {
if (is_sql_prepare()) if (is_sql_prepare())
thd->protocol_text.send_out_parameters(&this->lex->param_list); thd->protocol_text.send_out_parameters(&this->lex->param_list);
...@@ -3777,7 +3777,6 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) ...@@ -3777,7 +3777,6 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
thd->protocol->send_out_parameters(&this->lex->param_list); thd->protocol->send_out_parameters(&this->lex->param_list);
} }
/* /*
Log COM_EXECUTE to the general log. Note, that in case of SQL Log COM_EXECUTE to the general log. Note, that in case of SQL
prepared statements this causes two records to be output: prepared statements this causes two records to be output:
......
...@@ -19373,7 +19373,7 @@ static struct my_tests_st my_tests[]= { ...@@ -19373,7 +19373,7 @@ static struct my_tests_st my_tests[]= {
#endif #endif
{ "test_bug41078", test_bug41078 }, { "test_bug41078", test_bug41078 },
{ "test_bug44495", test_bug44495 }, { "test_bug44495", test_bug44495 },
/* XXX { "test_bug49972", test_bug49972 }, */ { "test_bug49972", test_bug49972 },
{ 0, 0 } { 0, 0 }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment