Skip to content

Commit 5138672

Browse files
author
Venkatesh Duggirala
committed
Bug#18742916 MYSQLBINLOG --RAW DOES NOT CHECK FOR ERRORS
Problem: mysqlbinlog --raw does not check for fail write errors Analysis: We have two my_fwrite calls in mysqlbinlog.cc file which does not check for failures. If my_fwrite returns error and if we are not catching the error we could end up in corrupting written out binary logs without reporting any errors/warnings. Fix: catch my_fwrite return values in those two places and throw error if fails.
1 parent 3f36b94 commit 5138672

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

client/mysqlbinlog.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,8 +2320,14 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
23202320
error("Could not create log file '%s'", log_file_name);
23212321
DBUG_RETURN(ERROR_STOP);
23222322
}
2323-
my_fwrite(result_file, (const uchar*) BINLOG_MAGIC,
2324-
BIN_LOG_HEADER_SIZE, MYF(0));
2323+
DBUG_EXECUTE_IF("simulate_result_file_write_error_for_FD_event",
2324+
DBUG_SET("+d,simulate_fwrite_error"););
2325+
if (my_fwrite(result_file, (const uchar*) BINLOG_MAGIC,
2326+
BIN_LOG_HEADER_SIZE, MYF(MY_NABP)))
2327+
{
2328+
error("Could not write into log file '%s'", log_file_name);
2329+
DBUG_RETURN(ERROR_STOP);
2330+
}
23252331
/*
23262332
Need to handle these events correctly in raw mode too
23272333
or this could get messy
@@ -2344,7 +2350,13 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
23442350

23452351
if (raw_mode)
23462352
{
2347-
my_fwrite(result_file, net->read_pos + 1 , len - 1, MYF(0));
2353+
DBUG_EXECUTE_IF("simulate_result_file_write_error",
2354+
DBUG_SET("+d,simulate_fwrite_error"););
2355+
if (my_fwrite(result_file, net->read_pos + 1 , len - 1, MYF(MY_NABP)))
2356+
{
2357+
error("Could not write into log file '%s'", log_file_name);
2358+
retval= ERROR_STOP;
2359+
}
23482360
if (ev)
23492361
{
23502362
ev->temp_buf=0;

mysql-test/r/mysqlbinlog.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,5 +969,10 @@ DELIMITER ;
969969
ROLLBACK /* added by mysqlbinlog */;
970970
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
971971
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
972+
#
973+
# Bug#18742916 : MYSQLBINLOG --RAW DOES NOT CHECK FOR ERRORS
974+
#
975+
ERROR: Could not write into log file 'MYSQLTEST_VARDIR/tmp/master-bin.000001'
976+
ERROR: Could not write into log file 'MYSQLTEST_VARDIR/tmp/master-bin.000001'
972977

973978
End of tests

mysql-test/t/mysqlbinlog.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,19 @@ eval SET GLOBAL SERVER_ID = $old_server_id;
563563

564564
--exec $MYSQL_BINLOG -uroot --password="" std_data/master-bin.000001 2>&1
565565

566+
--echo #
567+
--echo # Bug#18742916 : MYSQLBINLOG --RAW DOES NOT CHECK FOR ERRORS
568+
--echo #
569+
570+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
571+
--error 1
572+
--exec $MYSQL_BINLOG -#d,simulate_result_file_write_error_for_FD_event --raw --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT -r$MYSQLTEST_VARDIR/tmp/ master-bin.000001 2>&1
573+
574+
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
575+
--error 1
576+
--exec $MYSQL_BINLOG -#d,simulate_result_file_write_error --raw --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT -r$MYSQLTEST_VARDIR/tmp/ master-bin.000001 2>&1
577+
# Cleanup
578+
--remove_file $MYSQLTEST_VARDIR/tmp/master-bin.000001
579+
566580
--echo
567581
--echo End of tests

mysys/my_fstream.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -104,6 +104,7 @@ size_t my_fwrite(FILE *stream, const uchar *Buffer, size_t Count, myf MyFlags)
104104
DBUG_ENTER("my_fwrite");
105105
DBUG_PRINT("my",("stream: 0x%lx Buffer: 0x%lx Count: %u MyFlags: %d",
106106
(long) stream, (long) Buffer, (uint) Count, MyFlags));
107+
DBUG_EXECUTE_IF("simulate_fwrite_error", DBUG_RETURN(-1););
107108

108109
#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
109110
errors=0;

0 commit comments

Comments
 (0)