Below is the list of changes that have just been committed into a local
4.1 repository of msvensson. When msvensson does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.2290 05/06/13 21:54:20 msvensson@neptunus.(none) +5 -0
BUG#9358 mysqldump crashes if tablename starts with \
mysql-test/t/mysqldump.test
1.34 05/06/13 21:54:17 msvensson@neptunus.(none) +78 -0
Added test fro illegal/nonexisting table and database names
mysql-test/r/mysqldump.result
1.46 05/06/13 21:54:17 msvensson@neptunus.(none) +27 -0
Added test fro illegal/nonexisting table and database names
mysql-test/mysql-test-run.sh
1.253 05/06/13 21:54:17 msvensson@neptunus.(none) +3 -0
export BASEDIR
client/mysqltest.c
1.164 05/06/13 21:54:17 msvensson@neptunus.(none) +7 -2
Add DBUG_* printout
Make it possible to exec a command that fails by setting --error <errno> before
the command to exec.
client/mysqldump.c
1.189 05/06/13 21:54:17 msvensson@neptunus.(none) +88 -25
Add description of quote_for_like
Add quoting of \ to \\\\ in quote_for_like
Add DBUG_*
Rearranged code in dump_selected_tables so the first thing it will do is to check that
the tables to dump are available
Unless --force is used, program will exit if not all specified tables can be found
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: msvensson
# Host: neptunus.(none)
# Root: /home/msvensson/mysql/bug9358
--- 1.188/client/mysqldump.c 2005-05-20 15:56:00 +02:00
+++ 1.189/client/mysqldump.c 2005-06-13 21:54:17 +02:00
@@ -955,7 +955,28 @@
return buff;
} /* quote_name */
+/*
+ Quote a table name so it can be used in "SHOW TABLES LIKE <tabname>"
+
+ SYNOPSIS
+ quote_for_like
+ name - name of the table
+ buff - quoted name of the table
+
+ DESCRIPTION
+ Quote \, _, ' and % characters
+ Note: Because MySQL uses the C escape syntax in strings
+ (for example, '\n' to represent newline), you must double
+ any '\' that you use in your LIKE strings. For example, to
+ search for '\n', specify it as '\\n'. To search for '\', specify
+ it as '\\\\' (the backslashes are stripped once by the parser
+ and another time when the pattern match is done, leaving a
+ single backslash to be matched).
+
+ Example: "t\1" => "t\\\\1"
+
+*/
static char *quote_for_like(const char *name, char *buff)
{
@@ -963,7 +984,13 @@
*to++= '\'';
while (*name)
{
- if (*name == '\'' || *name == '_' || *name == '\\' || *name == '%')
+ if (*name == '\\')
+ {
+ *to++='\\';
+ *to++='\\';
+ *to++='\\';
+ }
+ else if (*name == '\'' || *name == '_' || *name == '%')
*to++= '\\';
*to++= *name++;
}
@@ -1114,6 +1141,7 @@
FILE *sql_file = md_result_file;
int len;
DBUG_ENTER("getTableStructure");
+ DBUG_PRINT("enter", ("db: %s, table: %s", db, table));
if (!insert_pat_inited)
{
@@ -2165,6 +2193,7 @@
char query[50 + 2*NAME_LEN];
char show_name_buff[FN_REFLEN];
DBUG_ENTER("get_actual_table_name");
+ DBUG_PRINT("enter", ("old_table_name: %s", old_table_name));
/* Check memory for quote_for_like() */
DBUG_ASSERT(2*sizeof(old_table_name) < sizeof(show_name_buff));
@@ -2186,36 +2215,63 @@
row= mysql_fetch_row( tableRes );
strmake(new_table_name, row[0], buf_size-1);
retval = 0;
+ DBUG_PRINT("info", ("new_table_name: %s", new_table_name));
}
mysql_free_result(tableRes);
}
- return retval;
+ DBUG_PRINT("exit", ("retval: %d", retval));
+ DBUG_RETURN(retval);
}
static int dump_selected_tables(char *db, char **table_names, int tables)
{
- uint numrows;
+ uint numrows, newtables= 0, i;
char table_buff[NAME_LEN*+3];
+ char new_table_name[NAME_LEN];
+ DYNAMIC_STRING lock_tables_query;
+ DYNAMIC_STRING new_table_names;
+
+ DBUG_ENTER("dump_selected_tables");
if (init_dumping(db))
return 1;
- if (lock_tables)
+
+ init_dynamic_string(&lock_tables_query, "LOCK TABLES ", 256, 1024);
+ init_dynamic_string(&new_table_names, "", 256, 1024);
+ for (; tables > 0 ; tables-- , table_names++)
{
- DYNAMIC_STRING query;
- int i;
- init_dynamic_string(&query, "LOCK TABLES ", 256, 1024);
- for (i=0 ; i < tables ; i++)
+ /* the table name passed on commandline may be wrong case */
+ if (!get_actual_table_name( *table_names, new_table_name, sizeof(new_table_name) ))
{
- dynstr_append(&query, quote_name(table_names[i], table_buff, 1));
- dynstr_append(&query, " READ /*!32311 LOCAL */,");
+ /* Add found table name to lock_tables_query */
+ if (lock_tables)
+ {
+ dynstr_append(&lock_tables_query, quote_name(new_table_name, table_buff, 1));
+ dynstr_append(&lock_tables_query, " READ /*!32311 LOCAL */,");
+ }
+ /* Add found table name to new_table_names array */
+ dynstr_append(&new_table_names, new_table_name);
+ dynstr_append(&new_table_names, " ");
+ newtables++;
}
- if (mysql_real_query(sock, query.str, query.length-1))
+ else
+ {
+ my_printf_error(0,"Couldn't find table: \"%s\"\n", MYF(0),
+ *table_names);
+ safe_exit(EX_USAGE);
+ /* We shall countinue here, if --force was given */
+ }
+ }
+
+ if (lock_tables)
+ {
+ if (mysql_real_query(sock, lock_tables_query.str, lock_tables_query.length-1))
DBerror(sock, "when doing LOCK TABLES");
/* We shall countinue here, if --force was given */
- dynstr_free(&query);
}
+ dynstr_free(&lock_tables_query);
if (flush_logs)
{
if (mysql_refresh(sock, REFRESH_LOG))
@@ -2224,20 +2280,27 @@
}
if (opt_xml)
print_xml_tag1(md_result_file, "", "database name=", db, "\n");
- for (; tables > 0 ; tables-- , table_names++)
+
+ /* Dump each selected table */
+ DBUG_PRINT("info", ("newtables: %d, new_table_names: %s", newtables,
new_table_names.str));
+ char* from= new_table_names.str;
+ for (i= 0; i < newtables ; i++)
{
char new_table_name[NAME_LEN];
-
- /* the table name passed on commandline may be wrong case */
- 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;
- }
+ char *to= new_table_name;
+ while (*from && !my_isspace(charset_info, *from))
+ *to++=*from++;
+ *to++=0;
+ numrows = getTableStructure(new_table_name, db);
+ if (!dFlag && numrows > 0)
+ dumpTable(numrows, new_table_name);
+
+ while (*from && my_isspace(charset_info, *from))
+ *from++;
+ }
+ dynstr_free(&new_table_names);
+ my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
+ order_by= 0;
if (opt_xml)
{
fputs("</database>\n", md_result_file);
@@ -2245,7 +2308,7 @@
}
if (lock_tables)
mysql_query_with_error_report(sock, 0, "UNLOCK TABLES");
- return 0;
+ DBUG_RETURN(0);
} /* dump_selected_tables */
--- 1.252/mysql-test/mysql-test-run.sh 2005-05-25 11:10:07 +02:00
+++ 1.253/mysql-test/mysql-test-run.sh 2005-06-13 21:54:17 +02:00
@@ -688,6 +688,9 @@
if [ "x$USE_EMBEDDED_SERVER" = "x1" ]; then
MYSQL_CLIENT_TEST="$MYSQL_CLIENT_TEST -A --language=$LANGUAGE -A
--datadir=$SLAVE_MYDDIR -A --character-sets-dir=$CHARSETSDIR"
fi
+# Save path and name of mysqldump
+MYSQL_DUMP_DIR="$MYSQL_DUMP"
+export MYSQL_DUMP_DIR
MYSQL_DUMP="$MYSQL_DUMP --no-defaults -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD
$EXTRA_MYSQLDUMP_OPT"
MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --local-load=$MYSQL_TMP_DIR
$EXTRA_MYSQLBINLOG_OPT"
MYSQL_FIX_SYSTEM_TABLES="$MYSQL_FIX_SYSTEM_TABLES --no-defaults --host=localhost
--port=$MASTER_MYPORT --socket=$MASTER_MYSOCK --user=root --password=$DBPASSWD
--basedir=$BASEDIR --bindir=$CLIENT_BINDIR --verbose"
--- 1.163/client/mysqltest.c 2005-05-16 01:04:14 +02:00
+++ 1.164/client/mysqltest.c 2005-06-13 21:54:17 +02:00
@@ -781,7 +781,7 @@
}
else
v = var_reg + digit;
- return eval_expr(v, var_val, (const char**)&var_val_end);
+ DBUG_RETURN(eval_expr(v, var_val, (const char**)&var_val_end));
}
@@ -957,7 +957,12 @@
error= pclose(res_file);
if (error != 0)
- die("command \"%s\" failed", cmd);
+ {
+ if(q->abort_on_error)
+ die("command \"%s\" failed", cmd);
+ else
+ verbose_msg("command \"%s\" failed, continue anyway", cmd);
+ }
if (!disable_result_log)
{
--- 1.45/mysql-test/r/mysqldump.result 2005-05-20 15:56:00 +02:00
+++ 1.46/mysql-test/r/mysqldump.result 2005-06-13 21:54:17 +02:00
@@ -1349,3 +1349,30 @@
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
DROP TABLE t1;
+create database mysqldump_test_db;
+use mysqldump_test_db;
+create table t1(a varchar(30) primary key, b int not null);
+create table t2(a varchar(30) primary key, b int not null);
+create table t3(a varchar(30) primary key, b int not null);
+test_sequence
+------ Testing with illegal table names ------
+MYSQL_DUMP_DIR: Couldn't find table: "\d-2-1.sql"
+
+MYSQL_DUMP_DIR: Couldn't find table: "\t1"
+
+MYSQL_DUMP_DIR: Couldn't find table: "\t1"
+
+MYSQL_DUMP_DIR: Couldn't find table: "\\t1"
+
+MYSQL_DUMP_DIR: Couldn't find table: "t\1"
+
+MYSQL_DUMP_DIR: Couldn't find table: "t\1"
+
+MYSQL_DUMP_DIR: Couldn't find table: "t/1"
+
+test_sequence
+------ Testing with illegal database names ------
+MYSQL_DUMP_DIR: Got error: 1049: Unknown database 'mysqldump_test_d' when selecting the
database
+MYSQL_DUMP_DIR: Got error: 1102: Incorrect database name 'mysqld\ump_test_db' when
selecting the database
+drop table t1, t2, t3;
+drop database mysqldump_test_db;
--- 1.33/mysql-test/t/mysqldump.test 2005-05-20 15:56:00 +02:00
+++ 1.34/mysql-test/t/mysqldump.test 2005-06-13 21:54:17 +02:00
@@ -543,3 +543,81 @@
INSERT INTO t1 VALUES (1),(2),(3);
--exec $MYSQL_DUMP --add-drop-database --skip-comments --databases test
DROP TABLE t1;
+
+#
+# Testing with tables and databases that don't exists
+# or contains illegal characters
+# (Bug #9358 mysqldump crashes if tablename starts with \)
+#
+create database mysqldump_test_db;
+use mysqldump_test_db;
+create table t1(a varchar(30) primary key, b int not null);
+create table t2(a varchar(30) primary key, b int not null);
+create table t3(a varchar(30) primary key, b int not null);
+
+--disable_query_log
+select '------ Testing with illegal table names ------' as test_sequence ;
+--enable_query_log
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "\d-2-1.sql" 2>&1
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "\t1" 2>&1
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "\\t1" 2>&1
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "\\\\t1" 2>&1
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "t\1" 2>&1
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "t\\1" 2>&1
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "t/1" 2>&1
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments "mysqldump_test_db" "T_1"
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments "mysqldump_test_db" "T%1"
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments "mysqldump_test_db" "T'1"
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments "mysqldump_test_db" "T_1"
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments "mysqldump_test_db" "T_"
+
+--disable_query_log
+select '------ Testing with illegal database names ------' as test_sequence ;
+--enable_query_log
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1102
+--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_d 2>&1
+
+--replace_result $MYSQL_DUMP_DIR MYSQL_DUMP_DIR
+--error 1000
+--exec $MYSQL_DUMP --compact --skip-comments "mysqld\ump_test_db" 2>&1
+
+drop table t1, t2, t3;
+drop database mysqldump_test_db;
+
+
| Thread |
|---|
| • bk commit into 4.1 tree (msvensson:1.2290) BUG#9358 | msvensson | 13 Jun |