summaryrefslogtreecommitdiff
path: root/sql/sql_lex.h
diff options
context:
space:
mode:
authorAlexey Kopytov <Alexey.Kopytov@Sun.com>2010-05-21 15:23:48 +0400
committerAlexey Kopytov <Alexey.Kopytov@Sun.com>2010-05-21 15:23:48 +0400
commitc2ebb0ac882feadedd0bbca71277fd2de66aa957 (patch)
tree393cb5d35a1dc953f8e9fee7b6c06737b675ba9c /sql/sql_lex.h
parent36be33b0ad829732b76d87f6d618546014fd96de (diff)
downloadmariadb-git-c2ebb0ac882feadedd0bbca71277fd2de66aa957.tar.gz
Bug #42064: low memory crash when importing hex strings, in
Item_hex_string::Item_hex_string The status of memory allocation in the Lex_input_stream (called from the Parser_state constructor) was not checked which led to a parser crash in case of the out-of-memory error. The solution is to introduce new init() member function in Parser_state and Lex_input_stream so that status of memory allocation can be returned to the caller. mysql-test/r/error_simulation.result: Added a test case for bug #42064. mysql-test/t/error_simulation.test: Added a test case for bug #42064. mysys/my_alloc.c: Added error injection code for the regression test. mysys/my_malloc.c: Added error injection code for the regression test. mysys/safemalloc.c: Added error injection code for the regression test. sql/event_data_objects.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/mysqld.cc: Added error injection code for the regression test. sql/sp.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/sql_lex.cc: Moved memory allocation from constructor to the separate init() member function. Added error injection code for the regression test. sql/sql_lex.h: Moved memory allocation from constructor to the separate init() member function. sql/sql_parse.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/sql_partition.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/sql_prepare.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/sql_trigger.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/sql_view.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures.. sql/thr_malloc.cc: Added error injection code for the regression test.
Diffstat (limited to 'sql/sql_lex.h')
-rw-r--r--sql/sql_lex.h48
1 files changed, 44 insertions, 4 deletions
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 54eefa22a59..184d24ee5b6 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1147,9 +1147,38 @@ enum enum_comment_state
class Lex_input_stream
{
public:
- Lex_input_stream(THD *thd, const char* buff, unsigned int length);
- ~Lex_input_stream();
+ Lex_input_stream() :
+ yylineno(1),
+ yytoklen(0),
+ yylval(NULL),
+ m_tok_start(NULL),
+ m_tok_end(NULL),
+ m_tok_start_prev(NULL),
+ m_echo(TRUE),
+ m_cpp_tok_start(NULL),
+ m_cpp_tok_start_prev(NULL),
+ m_cpp_tok_end(NULL),
+ m_body_utf8(NULL),
+ m_cpp_utf8_processed_ptr(NULL),
+ next_state(MY_LEX_START),
+ found_semicolon(NULL),
+ stmt_prepare_mode(FALSE),
+ in_comment(NO_COMMENT),
+ m_underscore_cs(NULL)
+ {
+ }
+
+ ~Lex_input_stream()
+ {
+ }
+
+ /**
+ Object initializer. Must be called before usage.
+ @retval FALSE OK
+ @retval TRUE Error
+ */
+ bool init(THD *thd, const char *buff, unsigned int length);
/**
Set the echo mode.
@@ -1930,10 +1959,21 @@ public:
class Parser_state
{
public:
- Parser_state(THD *thd, const char* buff, unsigned int length)
- : m_lip(thd, buff, length), m_yacc()
+ Parser_state()
+ : m_yacc()
{}
+ /**
+ Object initializer. Must be called before usage.
+
+ @retval FALSE OK
+ @retval TRUE Error
+ */
+ bool init(THD *thd, const char *buff, unsigned int length)
+ {
+ return m_lip.init(thd, buff, length);
+ }
+
~Parser_state()
{}