summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorunknown <jimw@mysql.com>2005-06-09 19:44:59 +0200
committerunknown <jimw@mysql.com>2005-06-09 19:44:59 +0200
commit3841a370a16632a16b7e1984c73fd03ab1a2b228 (patch)
treef1c7dd26401d453b6f00cf0b671edf0323620b15 /client
parentf9a80b34c7b55719427b46e98aa51bee26ea08d7 (diff)
downloadmariadb-git-3841a370a16632a16b7e1984c73fd03ab1a2b228.tar.gz
Fix use of _cgets() to handle an input line that exceeds our buffer space
before a newline is found. (Bug #10840) client/mysql.cc: Call _cgets() as many times as necessary to get the full line of input
Diffstat (limited to 'client')
-rw-r--r--client/mysql.cc21
1 files changed, 20 insertions, 1 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index f7fab85d095..b9b9b938da0 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -931,6 +931,7 @@ static int read_lines(bool execute_commands)
{
#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__)
char linebuffer[254];
+ String buffer;
#endif
char *line;
char in_string=0;
@@ -972,9 +973,24 @@ static int read_lines(bool execute_commands)
*p = '\0';
}
#else
+ buffer.length(0);
/* _cgets() expects the buffer size - 3 as the first byte */
linebuffer[0]= (char) sizeof(linebuffer) - 3;
- line= _cgets(linebuffer);
+ do
+ {
+ line= _cgets(linebuffer);
+ buffer.append(line, (unsigned char)linebuffer[1]);
+ /*
+ If _cgets() gets an input line that is linebuffer[0] bytes
+ long, the next call to _cgets() will return immediately with
+ linebuffer[1] == 0, and it does the same thing for input that
+ is linebuffer[0]-1 bytes long. So it appears that even though
+ _cgets() replaces the newline (which is two bytes on Window) with
+ a nil, it still needs the space in the linebuffer for it. This is,
+ naturally, undocumented.
+ */
+ } while (linebuffer[0] <= linebuffer[1] + 1);
+ line= buffer.c_ptr();
#endif /* __NETWARE__ */
#else
if (opt_outfile)
@@ -1031,6 +1047,9 @@ static int read_lines(bool execute_commands)
status.exit_status=0;
}
}
+#if defined( __WIN__) || defined(OS2) || defined(__NETWARE__)
+ buffer.free();
+#endif
return status.exit_status;
}