Re: mysql_stmt_execute() trashing stack
Posted by:
John Deal
Date: August 11, 2011 04:11PM
More work on this problem. I ran my server (compiled with -O0 and -g) with valgrind. Valgrind flagged illegal read of 4 bytes at the same time my stack guard discovered a write in the guard area.
I then built my server and ran it on a 32-bit system Ubuntu 10.4 server using MySQL 10.4 MySQL Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (i486) which is a somewhat later revision of MySql 5.1 than on the 64-bit system. The stack guard did not discover a write to the guard area but the return of the method containing the offending mysql_stmt_execute() statement and stack guard area had a trashed stack and segfaulted upon attempting to return to the caller.
Back to my 64-bit system, I did several other experiments including resetting the statement with mysql_stmt_reset() to no avail. I wound up re-preparing the offending mysql_stmt_execute() each time it is used and that seem to fix the problem (although defeats the benefits of prepared statements).
The relevant code is below (minus the stack guard check).
memset(bind, 0, sizeof(bind)); // Initialize MYSQL_BIND structure.
bind[0].buffer_type = MYSQL_TYPE_LONG;
bind[0].buffer = (char*) &user_id;
bind[0].buffer_length = sizeof(user_id);
lengths[0] = sizeof(user_id);
bind[0].length = &lengths[0];
bind[0].is_null = (my_bool*) 0;
bind[0].is_unsigned = true;
bind[0].error = &truncation_flags[0]; // DEBUG!:JRD
if (mysql_stmt_bind_param(m_prep_get_subscription_workplace_list, bind)
!= m_mysql_ok)
{ // Binding failed.
cout << "Error (DbMySqlDirectory::get_user_subscription_workplace_list): Binding of user_id failed. Message: "
<< mysql_stmt_error(m_prep_get_subscription_workplace_list) << endl;
return work_subscription_list;
}
if (mysql_stmt_execute(m_prep_get_subscription_workplace_list)
!= m_mysql_ok)
{
cout << "Error (DbMySqlDirectory::get_user_subscription_workplace_list): Execute of subscription list fetch for user_id: "
<< user_id << " failed. Message: "
<< mysql_stmt_error(m_prep_get_subscription_workplace_list) << endl;
return work_subscription_list;
}
This code executes fine except mysql_stmt_execute() writes on parts of the stack that it should not.
I have spent about a month off and on debugging his problem. I am going to leave the extra prepare for this one query and move on for now. I am still very mystified why this call to mysql_stmt_execute() is trashing the stack.
Subject
Views
Written By
Posted
4735
July 26, 2011 11:42AM
1775
August 03, 2011 04:55PM
1953
August 06, 2011 11:29AM
2630
August 07, 2011 12:18PM
1650
August 07, 2011 12:26PM
Re: mysql_stmt_execute() trashing stack
2433
August 11, 2011 04:11PM
2190
August 13, 2011 01:25PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.