Bug #8057 Crash parsing SQL statement in mysql 4.1.7, 4.1.9
Submitted: 20 Jan 2005 19:56 Modified: 5 May 2005 9:30
Reporter: David Lee Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.7, 4.1.9 OS:Linux (Linux 2.4.22-1.2199.nptl)
Assigned to: Antony Curtis CPU Architecture:Any

[20 Jan 2005 19:56] David Lee
Description:
I'm getting a consistant crash of Mysqld RPM installation on  Linux 2.4.22-1.2199.npt executing the SQL

UPDATE orders set order_id_str = CONCAT( instance , order_id ) where order_id = LAST_INSERT_ID()

The stack traceback I'm gettig is

0x808e1b7 handle_segfault + 423
0x82e5a08 pthread_sighandler + 184
0x809bda7 free_items__FP4Item + 23
0x808720f end_statement__3THD + 95
0x80a213c mysql_parse__FP3THDPcUi + 220
0x809c718 dispatch_command__F19enum_server_commandP3THDPcUi + 1576
0x809c0e4 do_command__FP3THD + 196
0x809b797 handle_one_connection + 615
0x82e31bc pthread_start_thread + 220
0x830ca8a thread_start + 4

I changed the calling code to do 2 steps for the SQL, 1 retrieve the LAST_INSERT_ID then call the Update using substitution parameters and the crash went away.

How to repeat:
I doubt this is repeatable in any environment but my own ... the DB calls in the entire process of events is fairly complex.

The code causing the immedeat crash looked like this: (java)

pStmt = conn.prepareStatement( "UPDATE orders set order_id_str = CONCAT( instance , order_id ) where order_id = LAST_INSERT_ID()");   
pStmt.executeUpdate();

Changed to this avoided the crash:
int last_id = DBUtil.getLastInsertID(conn);
DBUtil.executeSQL(conn , "UPDATE orders set order_id_str = CONCAT( instance , order_id ) where order_id = ?" , last_id );

The stack trace implies an crash during the parsing so maybe there is a bug with this exact SQL string ? maybe a buffer overflow or something ?
[20 Jan 2005 20:40] MySQL Verification Team
Verified with 4.1.10 from latest BK on January 20th ...
[5 May 2005 9:30] Antony Curtis
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html