From 633207b549cfe95ad12604894324c831ff2e0f22 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Mar 2005 13:06:43 -0600 Subject: [PATCH 1/2] Bug #9175 seg fault on 'mysqldump --single-transaction --tab mysql nonexistent' My code in get_actual_tablename was not checking to make sure SHOW TABLES LIKE % was returning rows. Now I check that the resultset is not null and has at least 1 row before I process the table. mysqldump.c: Add code to get_actual_tablename() to guard against SHOW TABLES LIKE not returning any rows client/mysqldump.c: Add code to get_actual_tablename() to guard against SHOW TABLES LIKE not returning any rows --- client/mysqldump.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 0ff88bcbc73..2a9029244d4 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2113,10 +2113,10 @@ static int dump_all_tables_in_db(char *database) different case (e.g. T1 vs t1) RETURN - void + int - 0 if a tablename was retrieved. 1 if not */ -static void get_actual_table_name(const char *old_table_name, +static int get_actual_table_name(const char *old_table_name, char *new_table_name, int buf_size) { @@ -2137,9 +2137,19 @@ static void get_actual_table_name(const char *old_table_name, } tableRes= mysql_store_result( sock ); - row= mysql_fetch_row( tableRes ); - strmake(new_table_name, row[0], buf_size-1); - mysql_free_result(tableRes); + if (tableRes != NULL) + { + my_ulonglong numRows = mysql_num_rows(tableRes); + if (numRows > 0) + { + row= mysql_fetch_row( tableRes ); + strmake(new_table_name, row[0], buf_size-1); + return 0; + } + mysql_free_result(tableRes); + return 1; + } + return 1; } @@ -2179,11 +2189,12 @@ static int dump_selected_tables(char *db, char **table_names, int tables) char new_table_name[NAME_LEN]; /* the table name passed on commandline may be wrong case */ - get_actual_table_name( *table_names, new_table_name, sizeof(new_table_name) ); - - numrows = getTableStructure(new_table_name, db); - if (!dFlag && numrows > 0) - dumpTable(numrows, new_table_name); + if (!get_actual_table_name( *table_names, new_table_name, sizeof(new_table_name) )) + { + numrows = getTableStructure(new_table_name, db); + if (!dFlag && numrows > 0) + dumpTable(numrows, new_table_name); + } my_free(order_by, MYF(MY_ALLOW_ZERO_PTR)); order_by= 0; } From 5b3549e64c9b0bce76af0cd16364b998b267674f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 Mar 2005 08:37:18 -0600 Subject: [PATCH 2/2] Bug #9175 seg fault on 'mysqldump --single-transaction --tab mysql nonexistent' mysqldump.c: Fixed get_actual_table_name so that it calls mysql_free_result in all cases that a non-NULl result is returned client/mysqldump.c: Fixed get_actual_table_name so that it calls mysql_free_result in all cases that a non-NULl result is returned --- client/mysqldump.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 2a9029244d4..2573c812067 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2120,6 +2120,7 @@ static int get_actual_table_name(const char *old_table_name, char *new_table_name, int buf_size) { + int retval; MYSQL_RES *tableRes; MYSQL_ROW row; char query[50 + 2*NAME_LEN]; @@ -2137,6 +2138,7 @@ static int get_actual_table_name(const char *old_table_name, } tableRes= mysql_store_result( sock ); + retval = 1; if (tableRes != NULL) { my_ulonglong numRows = mysql_num_rows(tableRes); @@ -2144,12 +2146,11 @@ static int get_actual_table_name(const char *old_table_name, { row= mysql_fetch_row( tableRes ); strmake(new_table_name, row[0], buf_size-1); - return 0; + retval = 0; } mysql_free_result(tableRes); - return 1; } - return 1; + return retval; }