Bug #57450 mysql client enter in an infinite loop if the standard input is a directory
Submitted: 14 Oct 2010 8:17 Modified: 10 Feb 2011 18:52
Reporter: Rene' Cannao' Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1 , 5.5 OS:Linux
Assigned to: Dmitry Shulga CPU Architecture:Any
Tags: mysql client

[14 Oct 2010 8:17] Rene' Cannao'
Description:
mysql client enter in an infinite loop if the standard input is a directory

How to repeat:
shell> mysql < /tmp
mysql: Error reading file 'UNOPENED' (Errcode: 21)
mysql: Error reading file 'UNOPENED' (Errcode: 21)
mysql: Error reading^CCtrl-C -- exit!

(press ctrl-c to stop)

Suggested fix:
Immediately exit on error 21
[12 Nov 2010 10:44] Hartmut Holzgraefe
proposed fix to prevent endless loop on certain read errors
(for now for "I/O error" and "Is a directory")

=== modified file 'client/readline.cc'
--- client/readline.cc	2010-07-08 21:20:08 +0000
+++ client/readline.cc	2010-11-12 10:42:41 +0000
@@ -177,7 +177,16 @@
   /* Read in new stuff. */
   if ((read_count= my_read(buffer->file, (uchar*) buffer->end, read_count,
 			   MYF(MY_WME))) == MY_FILE_ERROR)
+  {
+    switch (my_errno)
+    {
+    case EIO:
+    case EISDIR:
+      buffer->eof = 1;
+      break;
+    }
     return (size_t) -1;
+  }
 
   DBUG_PRINT("fill_buff", ("Got %lu bytes", (ulong) read_count));
[3 Dec 2010 11:52] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/125930

3521 Dmitry Shulga	2010-12-03
      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 for type of input source.
      
      The solution is to check if stdin's file descriptor related to directory
      and exit from program if this case is true.
     @ client/readline.cc
        batch_readline_init() was modified: added checking for file mode
        and returning from function if input stream is a directory.
        
        fill_buffer() and intern_read_line() was modified: doesn't set eof flag
        if read failed with temporal error and try repeat this failed syscall.
[8 Dec 2010 9:43] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/126295

3521 Dmitry Shulga	2010-12-08
      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 for type of input source.
      
      The solution is to check if stdin's file descriptor related to directory
      and exit from program if this case is true.
     @ client/readline.cc
        batch_readline_init() was modified: added checking for file mode
        and returning from function if input stream is a directory.
        
        fill_buffer() and intern_read_line() was modified: doesn't set eof flag
        if read failed with temporal error and try repeat this failed syscall.
[8 Dec 2010 17:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/126352

3521 Dmitry Shulga	2010-12-08
      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 for type of input source.
      
      The solution is to check if stdin's file descriptor related to directory
      and exit from program if this case is true.
     @ client/readline.cc
        batch_readline_init() was modified: added checking for file mode
        and returning from function if input stream is a directory.
        
        fill_buffer() and intern_read_line() was modified: doesn't set eof flag
        if read failed with temporal error and try repeat this failed syscall.
[9 Dec 2010 5:54] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/126388

3521 Dmitry Shulga	2010-12-09
      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 for type of input source.
      
      The solution is to check if stdin's file descriptor related to directory
      and exit from program if this case is true.
     @ client/readline.cc
        batch_readline_init() was modified: added checking for file mode
        and returning from function if input stream is a directory.
        
        fill_buffer() and intern_read_line() was modified: doesn't set eof flag
        if read failed with temporal error and try repeat this failed syscall.
[14 Dec 2010 13:40] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/126774

3521 Dmitry Shulga	2010-12-14
      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 for type of input source.
      
      The solution is to check if stdin's file descriptor related to directory
      and exit from program if this case is true.
      
      Additionally, it was fixed a bug in processing of error returned by
      read syscal.
     @ client/readline.cc
        batch_readline_init() was modified: added checking for file mode
        and returning from function if input stream is a directory.
        
        intern_read_line() was modified: cancel reading from input if
        fill_buffer() returns -1, i.e. if call to read failed.
[16 Dec 2010 17:17] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/127103

3521 Dmitry Shulga	2010-12-16
      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 for type of input source.
      
      The solution is to check if stdin's file descriptor related to directory
      and exit from program if this case is true.
      
      Additionally, it was fixed a bug in processing of error returned by
      read syscal.
     @ client/readline.cc
        batch_readline_init() was modified: added checking for file mode
        and returning from function if input stream is a directory.
        
        intern_read_line() was modified: cancel reading from input if
        fill_buffer() returns -1, e.g. if call to read failed.
[12 Jan 2011 16:13] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/128543

3521 Dmitry Shulga	2011-01-12
      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 output parameter was introduced into functions batch_readline()
      and intern_read_line() in order to differentiate between
      cases of getting EOF and getting error on standard input.
      
      A new test case was added into mysql.test.
     @ client/my_readline.h
        Added third output parameter into batch_readline.
     @ client/mysql.cc
        read_and_execute() was modified: set status.exit_status to 1
        when a call to batch_readline() returns NULL and
        valriable have_sys_err is true.
     @ client/readline.cc
        intern_read_line() was modified: cancel reading from input if
        fill_buffer() returns -1, e.g. if call to read failed.
[19 Jan 2011 13:34] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/129190

3521 Dmitry Shulga	2011-01-19
      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 a call to batch_readline() returns NULL and
        the error data member of LINE_BUFFER structure is not equal to zero.
     @ 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.
[20 Jan 2011 9:59] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/129262

3564 Dmitry Shulga	2011-01-20
      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 a call to batch_readline() returns NULL and
        the error data member of LINE_BUFFER structure is not equal to zero.
     @ 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.
[2 Feb 2011 11:39] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130204

3521 Dmitry Shulga	2011-02-02
      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.
[4 Feb 2011 9:59] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130379

3576 Dmitry Shulga	2011-02-04
      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.
[4 Feb 2011 10:26] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130383

3301 Dmitry Shulga	2011-02-04 [merge]
      Auto-merge from mysql-5.1 for bug#57450.
[4 Feb 2011 10:32] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130384

3599 Dmitry Shulga	2011-02-04 [merge]
      Auto-merge from mysql-5.5 for bug#57450.
[5 Feb 2011 5:02] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130488

3577 Dmitry Shulga	2011-02-05
      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.
[5 Feb 2011 5:06] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130489

3304 Dmitry Shulga	2011-02-05 [merge]
      Auto-merge from mysql-5.1 for bug#57450.
[5 Feb 2011 5:08] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130490

3599 Dmitry Shulga	2011-02-05 [merge]
      Auto-merge from mysql-5.5 for bug#57450.
[5 Feb 2011 5:09] Bugs System
Pushed into mysql-5.1 5.1.56 (revid:dmitry.shulga@oracle.com-20110205050200-x15w33hb7pe64ixs) (version source revid:dmitry.shulga@oracle.com-20110205050200-x15w33hb7pe64ixs) (merge vers: 5.1.56) (pib:24)
[5 Feb 2011 5:09] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:dmitry.shulga@oracle.com-20110205050629-ympv0fhtb0vw64ff) (version source revid:dmitry.shulga@oracle.com-20110205050629-ympv0fhtb0vw64ff) (merge vers: 5.6.2) (pib:24)
[5 Feb 2011 5:10] Bugs System
Pushed into mysql-5.5 5.5.10 (revid:dmitry.shulga@oracle.com-20110205050415-gfqp8x23rhj84cw2) (version source revid:dmitry.shulga@oracle.com-20110205050415-gfqp8x23rhj84cw2) (merge vers: 5.5.10) (pib:24)
[5 Feb 2011 5:10] Dmitry Shulga
Pushed to mysql-5.1, mysql-5.5 and mysql-trunk.
[8 Feb 2011 14:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130740

3584 Dmitry Shulga	2011-02-08
      Follow up fix for bug#57450.
      
      batch_readline_init() was modified - return an error
      if the input source is a directory or a block device.
[9 Feb 2011 6:47] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130791

3586 Dmitry Shulga	2011-02-09
      Follow up fix for bug#57450.
      
      batch_readline_init() was modified - return an error
      if the input source is a directory or a block device.
      
      This follow-up is necessary because on some platforms,
      such as Solaris, call to read() from directory may be
      successful.
[9 Feb 2011 6:54] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130792

3321 Dmitry Shulga	2011-02-09 [merge]
      Automerge from mysql-5.1 for follow-up bug#57450.
[9 Feb 2011 6:58] Bugs System
Pushed into mysql-5.1 5.1.56 (revid:dmitry.shulga@oracle.com-20110209064612-1zmxmvn8cdzxg50s) (version source revid:dmitry.shulga@oracle.com-20110209064612-1zmxmvn8cdzxg50s) (merge vers: 5.1.56) (pib:24)
[9 Feb 2011 6:59] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:dmitry.shulga@oracle.com-20110209065659-g5oom6ou4a4d8j77) (version source revid:dmitry.shulga@oracle.com-20110209065659-g5oom6ou4a4d8j77) (merge vers: 5.6.2) (pib:24)
[9 Feb 2011 6:59] Bugs System
Pushed into mysql-5.5 5.5.10 (revid:dmitry.shulga@oracle.com-20110209065011-xcf53n62lwki8mgu) (version source revid:dmitry.shulga@oracle.com-20110209065011-xcf53n62lwki8mgu) (merge vers: 5.5.10) (pib:24)
[9 Feb 2011 11:19] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130834

3323 Dmitry Shulga	2011-02-09 [merge]
      Automerge from mysql-5.1 for follow-up bug#57450.
[9 Feb 2011 11:20] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130836

3588 Dmitry Shulga	2011-02-09
      Follow up fix for bug#57450.
      
      batch_readline_init() was modified - make check for 
      type of file for input stream unless target platform
      is WINDOWS since on this platform S_IFBLK is undefined.
[9 Feb 2011 11:24] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/130839

3624 Dmitry Shulga	2011-02-09 [merge]
      Automerge from mysql-5.5 for follow-up bug#57450.
[9 Feb 2011 11:31] Bugs System
Pushed into mysql-5.1 5.1.56 (revid:dmitry.shulga@oracle.com-20110209111317-d7sd6c5qwofmdrou) (version source revid:dmitry.shulga@oracle.com-20110209111317-d7sd6c5qwofmdrou) (merge vers: 5.1.56) (pib:24)
[9 Feb 2011 11:32] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:dmitry.shulga@oracle.com-20110209112112-62efv51tm3ugeowk) (version source revid:dmitry.shulga@oracle.com-20110209112112-62efv51tm3ugeowk) (merge vers: 5.6.2) (pib:24)
[9 Feb 2011 11:32] Bugs System
Pushed into mysql-5.5 5.5.10 (revid:dmitry.shulga@oracle.com-20110209111633-l1umznsnj5wqr0es) (version source revid:dmitry.shulga@oracle.com-20110209111633-l1umznsnj5wqr0es) (merge vers: 5.5.10) (pib:24)
[10 Feb 2011 18:52] Paul DuBois
Noted in 5.1.56, 5.5.10, 5.6.2 changelogs.

The mysql client went into an infinite loop if the standard input was 
a directory.