Bug #58165 | "my_empty_string" gets modified and causes LOAD DATA to fail and other crashes | ||
---|---|---|---|
Submitted: | 12 Nov 2010 14:25 | Modified: | 2 Mar 2011 3:27 |
Reporter: | Shane Bester (Platinum Quality Contributor) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S1 (Critical) |
Version: | 5.1.54, 5.5.7 | OS: | Any |
Assigned to: | Martin Hansson | CPU Architecture: | Any |
Tags: | LOAD DATA, my_empty_string, select into outfile |
[12 Nov 2010 14:25]
Shane Bester
[12 Nov 2010 14:48]
MySQL Verification Team
Here is the initialization of line_start and enclosed from the global variable my_empty_string: sql_exchange::sql_exchange(char *name,bool flag) :file_name(name), opt_enclosed(0), dumpfile(flag), skip_lines(0) { field_term= &default_field_term; enclosed= line_start= &my_empty_string;
[12 Nov 2010 15:08]
Andrii Nikitin
Verified on 5.1.52 Mac 10.5 64bit after several executions of testcase: mysql [localhost] {msandbox} (test) > select 1 into outfile '/tmp/sdfsadfsd'; ERROR 1083 (42000): Field separator argument is not what is expected; check the manual
[12 Nov 2010 15:09]
Andrii Nikitin
full log
Attachment: corruption.log (application/octet-stream, text), 7.69 KiB.
[12 Nov 2010 15:26]
MySQL Verification Team
workaround is to always specify the 'fields enclosed by' and 'lines starting by' values explicitly
[15 Nov 2010 7:47]
MySQL Verification Team
my_empty_string destructor also crashes debug server at shutdown. it was a trigger to cause of bug 52353
[15 Dec 2010 11:00]
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/126915 3525 Martin Hansson 2010-12-15 Bug#58165: "my_empty_string" gets modified and causes LOAD DATA to fail and other crashes The string manipulating function insert() used a shared string buffer intended to always contain an empty string. Fixed by copying the buffer before modifying it. Relevant code has also been documented.
[16 Dec 2010 12:36]
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/127062 3525 Martin Hansson 2010-12-16 Bug#58165: "my_empty_string" gets modified and causes LOAD DATA to fail and other crashes The string manipulating SQL function insert() used a shared string buffer intended to contain an immutable empty string causing errors. With our code base this design faced two obstacles. The implementations of string valued SQL functions return pointers to String objects rather than the objects themselves and even if this were rectified we still have no protection against manipulation of shared string buffers. Fixed by always allocating a new String object whenever a function returns an empty string. Relevant code has also been documented.
[22 Dec 2010 9:50]
MySQL Verification Team
How sure are we that this problem is limited to the INSERT() string function? Is there a way to catch this problem with a debug assertion or something so we can test all functions in an automated way?
[22 Dec 2010 10:57]
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/127496 3525 Martin Hansson 2010-12-22 Bug#58165: "my_empty_string" gets modified and causes LOAD DATA to fail and other crashes The string manipulating SQL function insert() used a shared string buffer intended to contain an immutable empty string causing errors. With our code base this design faced two obstacles. The implementations of string valued SQL functions return pointers to String objects rather than the objects themselves and even if this were rectified we still have no protection against manipulation of shared string buffers. Fixed by always allocating a new String object whenever a function returns an empty string. Relevant code has also been documented.
[22 Dec 2010 12:30]
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/127501 3534 Martin Hansson 2010-12-22 Bug#58165: "my_empty_string" gets modified and causes LOAD DATA to fail and other crashes Some string manipulating SQL functions use a shared string buffer intended to contain an immutable empty string. This buffer was used by the SQL function SUBSTRING_INDEX() to return an empty string when one argument was of the wrong datatype. If the string was then modified by the sql function INSERT(), undefined behavior ensued. Fixed by allocating a new String buffer when SUBSTRING_INDEX() returns an empty string due to errors, and returning NULL should it fail. Relevant code has also been documented.
[28 Dec 2010 8: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/127616 3534 Martin Hansson 2010-12-28 Bug#58165: "my_empty_string" gets modified and causes LOAD DATA to fail and other crashes Some string manipulating SQL functions use a shared string object intended to contain an immutable empty string. This objectt was used by the SQL function SUBSTRING_INDEX() to return an empty string when one argument was of the wrong datatype. If the string object was then modified by the sql function INSERT(), undefined behavior ensued. Fixed by instead modifying the string object representing the function's result value when SUBSTRING_INDEX() returns an empty string due to errors. Relevant code has also been documented.
[30 Dec 2010 9: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/127704 3537 Martin Hansson 2010-12-30 Bug#58165: "my_empty_string" gets modified and causes LOAD DATA to fail and other crashes Some string manipulating SQL functions use a shared string object intended to contain an immutable empty string. This object was used by the SQL function SUBSTRING_INDEX() to return an empty string when one argument was of the wrong datatype. If the string object was then modified by the sql function INSERT(), undefined behavior ensued. Fixed by instead modifying the string object representing the function's result value whenever string manipulating SQL functions return an empty string. Relevant code has also been documented.
[30 Dec 2010 9:41]
Alexander Barkov
http://lists.mysql.com/commits/127704 is Ok to push. Thanks for adding code comments!
[30 Dec 2010 10: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/127707 3229 Martin Hansson 2010-12-30 [merge] Merge of fix for Bug#58165.
[30 Dec 2010 13:00]
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/127717 3475 Martin Hansson 2010-12-30 [merge] Merge of fix for Bug#58165.
[13 Jan 2011 7:57]
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/128585 3547 Martin Hansson 2011-01-13 Bug#58165: "my_empty_string" gets modified and causes LOAD DATA to fail and other crashes Some string manipulating SQL functions use a shared string object intended to contain an immutable empty string. This object was used by the SQL function SUBSTRING_INDEX() to return an empty string when one argument was of the wrong datatype. If the string object was then modified by the sql function INSERT(), undefined behavior ensued. Fixed by instead modifying the string object representing the function's result value whenever string manipulating SQL functions return an empty string. Relevant code has also been documented.
[13 Jan 2011 8: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/128586 3233 Martin Hansson 2011-01-13 [merge] Merge of fix for Bug#58165.
[13 Jan 2011 8: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/128587 3494 Martin Hansson 2011-01-13 [merge] Merge of fix for Bug#58165.
[13 Jan 2011 8:21]
Bugs System
Pushed into mysql-trunk 5.6.2 (revid:martin.hansson@oracle.com-20110113081952-n7mg2swpu1xb5fjp) (version source revid:martin.hansson@oracle.com-20110113081952-n7mg2swpu1xb5fjp) (merge vers: 5.6.2) (pib:24)
[13 Jan 2011 8:22]
Bugs System
Pushed into mysql-5.1 5.1.55 (revid:martin.hansson@oracle.com-20110113075715-2q5k9c2xk19lq2bg) (version source revid:martin.hansson@oracle.com-20110113075715-2q5k9c2xk19lq2bg) (merge vers: 5.1.55) (pib:24)
[13 Jan 2011 8:22]
Bugs System
Pushed into mysql-5.5 5.5.9 (revid:martin.hansson@oracle.com-20110113080721-bu92czxpaw9nht9k) (version source revid:martin.hansson@oracle.com-20110113080721-bu92czxpaw9nht9k) (merge vers: 5.5.9) (pib:24)
[2 Mar 2011 3:27]
Paul DuBois
Noted in 5.1.56, 5.5.10, 5.6.2 changelogs. Some string manipulating SQL functions use a shared string object intended to contain an immutable empty string. This object was used by the SQL function SUBSTRING_INDEX() to return an empty string when one argument was of the wrong datatype. If the string object was then modified by the SQL function INSERT(), undefined behavior ensued. CHANGESET - http://lists.mysql.com/commits/128587