Bug #11656 Server crash with mysql_stmt_fetch (cursors)
Submitted: 30 Jun 2005 8:32 Modified: 1 Jul 2005 13:14
Reporter: Georg Richter Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.9 OS:Linux (Linux)
Assigned to: Konstantin Osipov CPU Architecture:Any

[30 Jun 2005 8:32] Georg Richter
Description:
see how to repeat

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

MYSQL_STMT *open_cursor(MYSQL *mysql, char *query)
{
	ulong ctype = CURSOR_TYPE_READ_ONLY;
    MYSQL_STMT *stmt = mysql_stmt_init(mysql);

	mysql_stmt_prepare(stmt, query, strlen(query));
	mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &ctype);

	return stmt;
}

int main() {
	MYSQL *mysql;
	MYSQL_STMT *stmt;
	MYSQL_BIND bind[2];
	char buf[2][100];
	unsigned long len[2];
	int i, rc;
	
	mysql = mysql_init(NULL);
	mysql_real_connect(mysql, "localhost", "root", "", "test", 0, NULL, 0);

	mysql_query(mysql, "CREATE TABLE SRTM_ACT (SERVER varchar(40) collate latin1_bin NOT NULL default ' '," \
                                              "TEST_KIND varchar(1) collate latin1_bin NOT NULL default ' ', " \
                                              "TEST_ID varchar(30) collate latin1_bin NOT NULL default ' ', " \
                                              "PRIMARY KEY  (SERVER,TEST_KIND,TEST_ID)) ENGINE=InnoDB");

	stmt = open_cursor(mysql, "SELECT DISTINCT `TEST_KIND` ,`TEST_ID` FROM `SRTM_ACT` WHERE `SERVER` IN ( ? , ? )"); 

	strcpy(buf[0], "pcint502_MY2");
	strcpy(buf[1], "*");

	memset(bind, '\0', 2 * sizeof(MYSQL_BIND));
	for (i=0; i < 2; i++) {
		bind[i].buffer_type= MYSQL_TYPE_STRING;
		bind[i].buffer= (gptr *)&buf[i];
		bind[i].buffer_length= strlen(buf[i]);
	}

	mysql_stmt_bind_param(stmt, bind);

	mysql_stmt_execute(stmt);

	/* Here the server  crashes :-( */
	rc = mysql_stmt_fetch(stmt);

	mysql_stmt_close(stmt);
	mysql_close(mysql);	
}
[30 Jun 2005 8:39] Georg Richter
added mysqld.trace.gz (debug output from server) - no stacktrace available
[30 Jun 2005 9:18] Georg Richter
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the original bug instead.

Thank you for your interest in MySQL.

Additional info:

see also bug #11281
[1 Jul 2005 13:12] 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/internals/26593