Bug #2811 Server crash after execute
Submitted: 15 Feb 2004 12:12 Modified: 7 Apr 2004 13:48
Reporter: Georg Richter Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1 OS:Linux (Linux/Windows)
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[15 Feb 2004 12:12] Georg Richter
Description:
Following sample (see howto-repeat) crashes server:

How to repeat:
#include <mysql.h>
#include <stdio.h>

void main() {
	MYSQL		*mysql;
	MYSQL_STMT	*stmt;
	char		query[512];

	mysql = mysql_init(NULL);
	mysql_real_connect(mysql, "localhost", "root", "", "test", 0, NULL, 0);

	mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))");

	/* there is no reason to create an existing table */
	strcpy(query, "CREATE TABLE t1 (a int)");
	stmt = mysql_prepare(mysql, query, strlen(query));

	/* This should give an error (table t1 already exists) */
	mysql_execute(stmt);
	printf("Error: %s\n", mysql_stmt_error(stmt));

	/* This should give the same error, but crashes server */
	mysql_execute(stmt);
	printf("Error: %s\n", mysql_stmt_error(stmt));

	mysql_stmt_close(stmt);
	mysql_close(mysql);
}
[17 Feb 2004 20:15] MySQL Verification Team
Verified against BK tree 2 days older:

/sql_parse.cpp

 case SQLCOM_CREATE_TABLE:
  {
    /* Skip first table, which is the table we are creating */
    TABLE_LIST *create_table= tables;
    tables= tables->next;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Point of the crash.

Below call stack:

>	mysqld.exe!mysql_execute_command(THD * thd=0x00e4e2e0)  Line 2125 + 0x3	C++
 	mysqld.exe!mysql_stmt_execute(THD * thd=0x00e4e2e0, char * packet=0x037671d9)  Line 1043 + 0x9	C++
 	mysqld.exe!dispatch_command(enum_server_command command=COM_EXECUTE, THD * thd=0x00e4e2e0, char * packet=0x037671d9, unsigned int packet_length=5)  Line 1377 + 0xd	C++
 	mysqld.exe!do_command(THD * thd=0x00e4e2e0)  Line 1237 + 0x31	C++
 	mysqld.exe!handle_one_connection(void * arg=0x00e4e2e0)  Line 1003 + 0x9	C++
 	mysqld.exe!pthread_start(void * param=0x0376bec8)  Line 63 + 0x7	C
 	mysqld.exe!_threadstart(void * ptd=0x00e4d9b8)  Line 173 + 0xd	C
 	kernel32.dll!77e6d33b()
[5 Apr 2004 14:22] Oleksandr Byelkin
ChangeSet 
  1.1772 04/04/06 00:10:43 bell@sanja.is.com.ua +3 -0 
  reverting table list to be able to use it in next PS call (BUG#2811)
[7 Apr 2004 13:48] Oleksandr Byelkin
Thank you for bug report, patch is now pushed in source repository.