Bug #19483 missing quote causes loop
Submitted: 2 May 2006 15:34 Modified: 2 May 2006 15:41
Reporter: wally piechocki Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:Server version: 4.0.24 OS:Linux (linux)
Assigned to: MySQL Verification Team CPU Architecture:Any

[2 May 2006 15:34] wally piechocki
Description:
mysql goes into a loop on the following sql. There is a missing quote in front of the string "bad text". This causes a loop...shouldn't the mysql syntax checker catch this and issue an error? Thanks.

DROP TABLE `test_table`;
CREATE TABLE `test_table` (
`val1` int(4) NOT NULL auto_increment,
`val2` varchar(50) NOT NULL default '',
`val3` varchar(50) NOT NULL default '',
`val4` varchar(50) NOT NULL default '',
PRIMARY KEY (`val1`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;

INSERT INTO `test_table` VALUES (1, 'some text', 'some text', bad
text');
INSERT INTO `test_table` VALUES (2, 'some text', 'some text', 'some
text');

How to repeat:
Problem is erpeatable, issuing same SQL query causes the loop and hanguop of the mysql server.

Suggested fix:
when scanning for syntax, keep a counter of quotes around strings (ignore escaped character quotes). When you get to the end of the query and you have an odd count, you have a missing quote. Don't let the syntax checker run off the end of the earth looking for the end of a string.
[2 May 2006 15:41] MySQL Verification Team
Thank you for the bug report. I was unable to repeat the behavior
reported on current source server. The mysql client behaves as
mentioned in our Manual:

miguel@hegel:~/dbs/4.0> bin/mysql -uroot test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.0.27-debug-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE TABLE `test_table` (
    -> `val1` int(4) NOT NULL auto_increment,
    -> `val2` varchar(50) NOT NULL default '',
    -> `val3` varchar(50) NOT NULL default '',
    -> `val4` varchar(50) NOT NULL default '',
    -> PRIMARY KEY (`val1`)
    -> ) TYPE=MyISAM AUTO_INCREMENT=3 ;
Query OK, 0 rows affected (0.03 sec)

mysql> INSERT INTO `test_table` VALUES (1, 'some text', 'some text', bad
    -> text');
    '> INSERT INTO `test_table` VALUES (2, 'some text', 'some text', 'some
    -> text');
    '> \c
    '> '
    -> \c
mysql> INSERT INTO `test_table` VALUES (1, 'some text', 'some text', bad
    -> text');
    '> 

Please try a most recent version.