diff options
author | Rohit Kalhans <rohit.kalhans@oracle.com> | 2012-08-08 22:15:46 +0530 |
---|---|---|
committer | Rohit Kalhans <rohit.kalhans@oracle.com> | 2012-08-08 22:15:46 +0530 |
commit | 941924e8319f62b3ef1cb8dfac07af115787ed7a (patch) | |
tree | 529c5476f33a30da76a33c1494c7fd77e2cec9b3 /client | |
parent | d4e4538b2de4894f35c556bcaf9baf0a010969a9 (diff) | |
download | mariadb-git-941924e8319f62b3ef1cb8dfac07af115787ed7a.tar.gz |
BUG#11757312: MYSQLBINLOG DOES NOT ACCEPT INPUT FROM STDIN
WHEN STDIN IS A PIPE
Problem: Mysqlbinlog does not accept the input from STDIN when
STDIN is a pipe. This prevents the users from passing the input file
through a shell pipe.
Background: The my_seek() function does not check if the file descriptor
passed to it is regular (seekable) file. The check_header() function in
mysqlbinlog calls the my_b_seek() unconditionally and it fails when
the underlying file is a PIPE.
Resolution: We resolve this problem by checking if the underlying file
is a regular file by using my_fstat() before calling my_b_seek().
If the underlying file is not seekable we skip the call to my_b_seek()
in check_header().
Diffstat (limited to 'client')
-rw-r--r-- | client/mysqlbinlog.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index ef67e0ffba9..c32f92ae149 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -36,6 +36,7 @@ #include "mysql_priv.h" #include "log_event.h" #include "sql_common.h" +#include "my_dir.h" #include <welcome_copyright_notice.h> // ORACLE_WELCOME_COPYRIGHT_NOTICE #define BIN_LOG_HEADER_SIZE 4 @@ -1767,6 +1768,7 @@ static Exit_status check_header(IO_CACHE* file, uchar header[BIN_LOG_HEADER_SIZE]; uchar buf[PROBE_HEADER_LEN]; my_off_t tmp_pos, pos; + MY_STAT my_file_stat; delete glob_description_event; if (!(glob_description_event= new Format_description_log_event(3))) @@ -1776,7 +1778,16 @@ static Exit_status check_header(IO_CACHE* file, } pos= my_b_tell(file); - my_b_seek(file, (my_off_t)0); + + /* fstat the file to check if the file is a regular file. */ + if (my_fstat(file->file, &my_file_stat, MYF(0)) == -1) + { + error("Unable to stat the file."); + return ERROR_STOP; + } + if ((my_file_stat.st_mode & S_IFMT) == S_IFREG) + my_b_seek(file, (my_off_t)0); + if (my_b_read(file, header, sizeof(header))) { error("Failed reading header; probably an empty file."); |