From b7a957d127181b07152504d302c2feb1e7366155 Mon Sep 17 00:00:00 2001 From: "dlenev@brandersnatch.localdomain" <> Date: Sun, 17 Oct 2004 13:59:46 +0400 Subject: [PATCH] Fix for bug #6081 "Call to deprecated mysql_create_db() function crashes server". Altough mysql_create_db()/mysql_drop_db() API calls are deprecated since 4.0, they should not crash server and should not stall connection in case of errors. --- sql/sql_parse.cc | 10 ++++++++-- tests/client_test.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index e7a013e19ea..7b182c4cfd9 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1556,6 +1556,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, case COM_CREATE_DB: // QQ: To be removed { char *db=thd->strdup(packet), *alias; + HA_CREATE_INFO create_info; statistic_increment(com_stat[SQLCOM_CREATE_DB],&LOCK_status); // null test to handle EOM @@ -1567,7 +1568,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (check_access(thd,CREATE_ACL,db,0,1,0)) break; mysql_log.write(thd,command,packet); - mysql_create_db(thd,(lower_case_table_names == 2 ? alias : db),0,0); + bzero(&create_info, sizeof(create_info)); + if (mysql_create_db(thd, (lower_case_table_names == 2 ? alias : db), + &create_info, 0) < 0) + send_error(thd, thd->killed ? ER_SERVER_SHUTDOWN : 0); break; } case COM_DROP_DB: // QQ: To be removed @@ -1588,7 +1592,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; } mysql_log.write(thd,command,db); - mysql_rm_db(thd, (lower_case_table_names == 2 ? alias : db), 0, 0); + if (mysql_rm_db(thd, (lower_case_table_names == 2 ? alias : db), + 0, 0) < 0) + send_error(thd, thd->killed ? ER_SERVER_SHUTDOWN : 0); break; } #ifndef EMBEDDED_LIBRARY diff --git a/tests/client_test.c b/tests/client_test.c index 0b30cc3386d..a8d63d2ed86 100644 --- a/tests/client_test.c +++ b/tests/client_test.c @@ -10541,6 +10541,33 @@ static void test_bug5315() } +/* + Altough mysql_create_db(), mysql_rm_db() are deprecated since 4.0 they + should not crash server and should not hang in case of errors. + + Since those functions can't be seen in modern API (unless client library + was compiled with USE_OLD_FUNCTIONS define) we use simple_command() macro. +*/ +static void test_bug6081() +{ + int rc; + myheader("test_bug6081"); + + rc= simple_command(mysql, COM_DROP_DB, current_db, + (ulong)strlen(current_db), 0); + myquery(rc); + rc= simple_command(mysql, COM_DROP_DB, current_db, + (ulong)strlen(current_db), 0); + myquery_r(rc); + rc= simple_command(mysql, COM_CREATE_DB, current_db, + (ulong)strlen(current_db), 0); + myquery(rc); + rc= simple_command(mysql, COM_CREATE_DB, current_db, + (ulong)strlen(current_db), 0); + myquery_r(rc); +} + + /* Read and parse arguments and MySQL options from my.cnf */ @@ -10851,6 +10878,7 @@ int main(int argc, char **argv) test_bug5194(); /* bulk inserts in prepared mode */ test_bug5315(); /* check that mysql_change_user closes all prepared statements */ + test_bug6081(); /* test of mysql_create_db()/mysql_rm_db() */ /* XXX: PLEASE RUN THIS PROGRAM UNDER VALGRIND AND VERIFY THAT YOUR TEST DOESN'T CONTAIN WARNINGS/ERRORS BEFORE YOU PUSH.