From: Jon Olav Hauglid Date: September 24 2010 8:44am Subject: bzr push into mysql-5.5-runtime branch (jon.hauglid:3144 to 3145) Bug#56678 List-Archive: http://lists.mysql.com/commits/119007 X-Bug: 56678 Message-Id: <201009240844.o8O7XLl2002609@rcsinet15.oracle.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8652287221116417610==" --===============8652287221116417610== MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 3145 Jon Olav Hauglid 2010-09-24 Bug #56678 Valgrind warnings from binlog.binlog_unsafe After the patch for Bug#54579, multi inserts done with INSERT DELAYED are binlogged as normal INSERT. During processing of the statement, a new query string without the DELAYED keyword is made. The problem was that this new string was incorrectly made when the INSERT DELAYED was part of a prepared statement - data was read outside the allocated buffer. The reason for this bug was that a pointer to the position of the DELAYED keyword inside the query string was stored when parsing the statement. This pointer was then later (at runtime) used (via pointer subtraction) to find the number of characters to skip when making a new query string without DELAYED. But when the statement was re-executed as part of a prepared statement, the original pointer would be invalid and the pointer subtraction would give a wrong/random result. This patch fixes the problem by instead storing the offsets from the beginning of the query string to the start and end of the DELAYED keyword. These values will not depend on the memory position of the query string at runtime and therefore not give wrong results when the statement is executed in a prepared statement. This bug was a regression introduced by the patch for Bug#54579. No test case added as this bug is already covered by the existing binlog.binlog_unsafe test case when running with valgrind. modified: sql/sql_insert.cc sql/sql_lex.h sql/sql_yacc.yy 3144 Jon Olav Hauglid 2010-09-24 Bug #54920 Stored functions are allowed in HANDLER statements, but broken. Before this patch, it was allowed to use stored functions in HANDLER ... READ statements. The problem was that this functionality was not really supported by the code. Proper locking would for example not be performed, and it was also possible to break replication by having stored functions that performed updates. This patch disallows the use of stored functions in HANDLER ... READ. Any such statement will now give an ER_NOT_SUPPORTED_YET error. This is an incompatible change and should be reflected in the documentation. Test case added to handler_myisam/handler_innodb.test. modified: mysql-test/include/handler.inc mysql-test/r/handler_innodb.result mysql-test/r/handler_myisam.result sql/sql_yacc.yy === modified file 'sql/sql_insert.cc' --- a/sql/sql_insert.cc 2010-09-15 14:15:31 +0000 +++ b/sql/sql_insert.cc 2010-09-24 08:44:09 +0000 @@ -634,14 +634,12 @@ bool open_and_lock_for_insert_delayed(TH static int create_insert_stmt_from_insert_delayed(THD *thd, String *buf) { - /* Append the part of thd->query before "DELAYED" keyword */ - if (buf->append(thd->query(), - thd->lex->keyword_delayed_begin - thd->query())) + /* Make a copy of thd->query() and then remove the "DELAYED" keyword */ + if (buf->append(thd->query()) || + buf->replace(thd->lex->keyword_delayed_begin_offset, + thd->lex->keyword_delayed_end_offset - + thd->lex->keyword_delayed_begin_offset, 0)) return 1; - /* Append the part of thd->query after "DELAYED" keyword */ - if (buf->append(thd->lex->keyword_delayed_begin + 7)) - return 1; - return 0; } === modified file 'sql/sql_lex.h' --- a/sql/sql_lex.h 2010-09-01 13:12:42 +0000 +++ b/sql/sql_lex.h 2010-09-24 08:44:09 +0000 @@ -2355,15 +2355,19 @@ struct LEX: public Query_tables_list This pointer is required to add possibly omitted DEFINER-clause to the DDL-statement before dumping it to the binlog. - keyword_delayed_begin points to the begin of the DELAYED keyword in - INSERT DELAYED statement. + keyword_delayed_begin_offset is the offset to the beginning of the DELAYED + keyword in INSERT DELAYED statement. keyword_delayed_end_offset is the + offset to the character right after the DELAYED keyword. */ union { const char *stmt_definition_begin; - const char *keyword_delayed_begin; + uint keyword_delayed_begin_offset; }; - const char *stmt_definition_end; + union { + const char *stmt_definition_end; + uint keyword_delayed_end_offset; + }; /** During name resolution search only in the table list given by === modified file 'sql/sql_yacc.yy' --- a/sql/sql_yacc.yy 2010-09-24 07:18:16 +0000 +++ b/sql/sql_yacc.yy 2010-09-24 08:44:09 +0000 @@ -10447,7 +10447,10 @@ insert_lock_option: | LOW_PRIORITY { $$= TL_WRITE_LOW_PRIORITY; } | DELAYED_SYM { - Lex->keyword_delayed_begin= YYLIP->get_tok_start(); + Lex->keyword_delayed_begin_offset= (uint)(YYLIP->get_tok_start() - + YYTHD->query()); + Lex->keyword_delayed_end_offset= Lex->keyword_delayed_begin_offset + + YYLIP->yyLength() + 1; $$= TL_WRITE_DELAYED; } | HIGH_PRIORITY { $$= TL_WRITE; } @@ -10457,7 +10460,10 @@ replace_lock_option: opt_low_priority { $$= $1; } | DELAYED_SYM { - Lex->keyword_delayed_begin= YYLIP->get_tok_start(); + Lex->keyword_delayed_begin_offset= (uint)(YYLIP->get_tok_start() - + YYTHD->query()); + Lex->keyword_delayed_end_offset= Lex->keyword_delayed_begin_offset + + YYLIP->yyLength() + 1; $$= TL_WRITE_DELAYED; } ; --===============8652287221116417610== MIME-Version: 1.0 Content-Type: text/bzr-bundle; charset="us-ascii"; name="bzr/jon.hauglid@stripped" Content-Transfer-Encoding: 7bit Content-Disposition: inline # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: jon.hauglid@stripped # target_branch: file:///export/home/x/mysql-5.5-runtime-bug56678/ # testament_sha1: 8e6c108872ce60c7aeca69bfba13498e523d7f96 # timestamp: 2010-09-24 10:44:42 +0200 # source_branch: file:///export/home/x/mysql-5.5-bugfixing/ # base_revision_id: jon.hauglid@stripped\ # fmk8i6ost9fp170w # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWQ4reFcAA9TfgFEQ2P///3Z3 3SC////+YAlnHOvmustNFZ6Y1pq2VTkaASptsJSIyJkymmNTNqnononqZAAGjTRpkADIEohBpPJp qaZAKPUaNPUP0kAAaAADQNCNGKk9QaaA0GjQAAGgAAAASaoQhGTaInqPFMIj9U8o0PSD1Mj0mgyZ PUAcZMmjEMTTAQMCaYIwTE000AGEEkRMgTEMgBGRkp+imKep6EaPRAYg02owE7bAXLc9N8YpFpp0 5qDPevauBmw7Yk14BZTTSLMOFrYQor1VSVpWhJ42FPzLYiBPBMV5FqY6UfaKoZmdel97Hr8ZSSqS TKQEijL9VTD9dP0nKW+JsFHDrn7TzRUWKG3Xce6GF/Gw6i/d0WNzV3c+ap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