diff --git a/mysql-test/r/ctype_cp932_binlog_stm.result b/mysql-test/r/ctype_cp932_binlog_stm.result index 75d05aa9f0aa0..c92026cf5a493 100644 --- a/mysql-test/r/ctype_cp932_binlog_stm.result +++ b/mysql-test/r/ctype_cp932_binlog_stm.result @@ -56,7 +56,7 @@ master-bin.000001 # Query # # use `test`; DROP TABLE `t4` /* generated by server End of 5.0 tests call mtr.add_suppression("Error in Log_event::read_log_event\\\(\\\): 'Found invalid"); SHOW BINLOG EVENTS FROM 504; -ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error +ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Invalid input pos specified please provide valid one. Bug#44352 UPPER/LOWER function doesn't work correctly on cp932 and sjis environment. CREATE TABLE t1 (a varchar(16)) character set cp932; INSERT INTO t1 VALUES (0x8372835E),(0x8352835E); diff --git a/mysql-test/suite/binlog/r/binlog_show_binlog_event_random_pos.result b/mysql-test/suite/binlog/r/binlog_show_binlog_event_random_pos.result index 358422c584245..c2e634ebe8243 100644 --- a/mysql-test/suite/binlog/r/binlog_show_binlog_event_random_pos.result +++ b/mysql-test/suite/binlog/r/binlog_show_binlog_event_random_pos.result @@ -9,4 +9,7 @@ INSERT INTO t1 VALUES (repeat('a', 255), repeat('a', 255),repeat('a', 255),repea INSERT INTO t1 VALUES (repeat('a', 255), repeat('a', 255),repeat('a', 255),repeat('a', 255),repeat('a', 255)); UPDATE t1 SET c1=repeat('b',255); INSERT INTO t1 VALUES (repeat('a', 255), repeat('a', 255),repeat('a', 255),repeat('a', 255),repeat('a', 255)); +SHOW BINLOG EVENTS FROM POS; +ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Invalid pos specified. Requested from pos:POS is greater than actual file size:MAX_POS + DROP TABLE t1; diff --git a/mysql-test/suite/binlog/t/binlog_show_binlog_event_random_pos.test b/mysql-test/suite/binlog/t/binlog_show_binlog_event_random_pos.test index e6a9e1cb2c1af..05e6967c538bf 100644 --- a/mysql-test/suite/binlog/t/binlog_show_binlog_event_random_pos.test +++ b/mysql-test/suite/binlog/t/binlog_show_binlog_event_random_pos.test @@ -34,4 +34,9 @@ while ($pos <= $max_pos) --enable_query_log } +# Testing a case where input position is greater than actual binlog file size. +--replace_result $pos POS $max_pos MAX_POS +--error 1220 +eval SHOW BINLOG EVENTS FROM $pos; + DROP TABLE t1; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 38c2b9b5b8ed9..8949af7cdcdc1 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -3842,6 +3842,7 @@ bool mysql_show_binlog_events(THD* thd) { Protocol *protocol= thd->protocol; List field_list; + char errmsg_buf[MYSYS_ERRMSG_SIZE]; const char *errmsg = 0; bool ret = TRUE; /* @@ -3856,6 +3857,9 @@ bool mysql_show_binlog_events(THD* thd) Master_info *mi= 0; LOG_INFO linfo; LEX_MASTER_INFO *lex_mi= &thd->lex->mi; + enum enum_binlog_checksum_alg checksum_alg; + my_off_t binlog_size; + MY_STAT s; DBUG_ENTER("mysql_show_binlog_events"); @@ -3904,10 +3908,6 @@ bool mysql_show_binlog_events(THD* thd) mi= 0; } - /* Validate user given position using checksum */ - if (lex_mi->pos == pos && !opt_master_verify_checksum) - verify_checksum_once= true; - unit->set_limit(thd->lex->current_select); limit_start= unit->offset_limit_cnt; limit_end= unit->select_limit_cnt; @@ -3934,6 +3934,17 @@ bool mysql_show_binlog_events(THD* thd) if ((file=open_binlog(&log, linfo.log_file_name, &errmsg)) < 0) goto err; + my_stat(linfo.log_file_name, &s, MYF(0)); + binlog_size= s.st_size; + if (lex_mi->pos > binlog_size) + { + sprintf(errmsg_buf, "Invalid pos specified. Requested from pos:%llu is " + "greater than actual file size:%lu\n", lex_mi->pos, + (ulong)s.st_size); + errmsg= errmsg_buf; + goto err; + } + /* to account binlog event header size */ @@ -3985,7 +3996,40 @@ bool mysql_show_binlog_events(THD* thd) } } - my_b_seek(&log, pos); + checksum_alg= description_event->checksum_alg; + /* Validate user given position using checksum */ + if (checksum_alg != BINLOG_CHECKSUM_ALG_OFF && + checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF) + { + if (lex_mi->pos == pos && !opt_master_verify_checksum) + verify_checksum_once= true; + my_b_seek(&log, pos); + } + else + { + my_off_t cur_pos= my_b_tell(&log); + uint next_event_len= 0; + uchar buff[IO_SIZE]; + while (cur_pos < pos) + { + my_b_seek(&log, cur_pos + EVENT_LEN_OFFSET); + if (my_b_read(&log, (uchar *)buff, sizeof(next_event_len))) + { + mysql_mutex_unlock(log_lock); + errmsg = "Could not read event_length"; + goto err; + } + next_event_len= *(uint*)buff; + cur_pos= cur_pos + next_event_len; + } + if (cur_pos > pos) + { + mysql_mutex_unlock(log_lock); + errmsg= "Invalid input pos specified please provide valid one."; + goto err; + } + my_b_seek(&log, cur_pos); + } for (event_count = 0; (ev = Log_event::read_log_event(&log, (mysql_mutex_t*) 0,