mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Fixed bug#57450 - mysql client enter in an infinite loop
if the standard input is a directory. The problem is that mysql monitor try to read from stdin without checking input source type. The solution is to stop reading data from standard input if a call to read(2) failed. A new test case was added into mysql.test. client/my_readline.h: Data members error and truncated was added to LINE_BUFFER structure. These data members used instead of out parameters in functions batch_readline, intern_read_line. client/mysql.cc: read_and_execute() was modified: set status.exit_status to 1 when the error occured while reading the next command line in non-interactive mode. Also the value of the truncated attribute of structure LINE_BUFF is taken into account only for non-iteractive mode. client/readline.cc: intern_read_line() was modified: cancel reading from input if fill_buffer() returns -1, e.g. if call to read failed. batch_readline was modified: set the error data member of LINE_BUFFER structure to value of my_errno when system error happened during call to my_read/my_realloc. mysql-test/t/mysql.test: Test for bug#57450 was added.
This commit is contained in:
@@ -1872,14 +1872,13 @@ static int read_and_execute(bool interactive)
|
||||
ulong line_number=0;
|
||||
bool ml_comment= 0;
|
||||
COMMANDS *com;
|
||||
bool truncated= 0;
|
||||
status.exit_status=1;
|
||||
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (!interactive)
|
||||
{
|
||||
line=batch_readline(status.line_buff, &truncated);
|
||||
line=batch_readline(status.line_buff);
|
||||
/*
|
||||
Skip UTF8 Byte Order Marker (BOM) 0xEFBBBF.
|
||||
Editors like "notepad" put this marker in
|
||||
@@ -1953,9 +1952,13 @@ static int read_and_execute(bool interactive)
|
||||
if (opt_outfile && line)
|
||||
fprintf(OUTFILE, "%s\n", line);
|
||||
}
|
||||
if (!line) // End of file
|
||||
// End of file or system error
|
||||
if (!line)
|
||||
{
|
||||
status.exit_status=0;
|
||||
if (status.line_buff && status.line_buff->error)
|
||||
status.exit_status= 1;
|
||||
else
|
||||
status.exit_status= 0;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1976,7 +1979,8 @@ static int read_and_execute(bool interactive)
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
if (add_line(glob_buffer,line,&in_string,&ml_comment, truncated))
|
||||
if (add_line(glob_buffer, line, &in_string, &ml_comment,
|
||||
status.line_buff ? status.line_buff->truncated : 0))
|
||||
break;
|
||||
}
|
||||
/* if in batch mode, send last query even if it doesn't end with \g or go */
|
||||
|
||||
Reference in New Issue
Block a user