Skip to content

Commit a43233f

Browse files
Bharathy Satishprashanttekriwal
authored andcommitted
Merge branch 'mysql-5.5' into mysql-5.6
(cherry picked from commit 7396facd28cc8fb6de7817c4e5978993b7267b6b)
1 parent f4165ea commit a43233f

File tree

3 files changed

+156
-13
lines changed

3 files changed

+156
-13
lines changed

client/mysqldump.c

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ static int dump_tablespaces_for_databases(char** databases);
582582
static int dump_tablespaces(char* ts_where);
583583
static void print_comment(FILE *sql_file, my_bool is_error, const char *format,
584584
...);
585+
static const char* fix_identifier_with_newline(char*);
585586

586587

587588
/*
@@ -682,7 +683,7 @@ static void write_header(FILE *sql_file, char *db_name)
682683
MACHINE_TYPE);
683684
print_comment(sql_file, 0, "-- Host: %s Database: %s\n",
684685
current_host ? current_host : "localhost",
685-
db_name ? db_name : "");
686+
db_name ? fix_identifier_with_newline(db_name) : "");
686687
print_comment(sql_file, 0,
687688
"-- ------------------------------------------------------\n"
688689
);
@@ -2036,6 +2037,30 @@ static void print_comment(FILE *sql_file, my_bool is_error, const char *format,
20362037
print_xml_comment(sql_file, strlen(comment_buff), comment_buff);
20372038
}
20382039

2040+
/*
2041+
This function accepts object names and prefixes -- wherever \n
2042+
character is found.
2043+
2044+
@param[in] object_name
2045+
2046+
@return
2047+
@retval fixed object name.
2048+
*/
2049+
2050+
static const char* fix_identifier_with_newline(char* object_name)
2051+
{
2052+
static char buff[COMMENT_LENGTH]= {0};
2053+
char *ptr= buff;
2054+
memset(buff, 0, 255);
2055+
while(*object_name)
2056+
{
2057+
*ptr++ = *object_name;
2058+
if (*object_name == '\n')
2059+
ptr= strmov(ptr, "-- ");
2060+
object_name++;
2061+
}
2062+
return buff;
2063+
}
20392064

20402065
/*
20412066
create_delimiter
@@ -2104,7 +2129,8 @@ static uint dump_events_for_db(char *db)
21042129

21052130
/* nice comments */
21062131
print_comment(sql_file, 0,
2107-
"\n--\n-- Dumping events for database '%s'\n--\n", db);
2132+
"\n--\n-- Dumping events for database '%s'\n--\n",
2133+
fix_identifier_with_newline(db));
21082134

21092135
/*
21102136
not using "mysql_query_with_error_report" because we may have not
@@ -2321,7 +2347,8 @@ static uint dump_routines_for_db(char *db)
23212347

23222348
/* nice comments */
23232349
print_comment(sql_file, 0,
2324-
"\n--\n-- Dumping routines for database '%s'\n--\n", db);
2350+
"\n--\n-- Dumping routines for database '%s'\n--\n",
2351+
fix_identifier_with_newline(db));
23252352

23262353
/*
23272354
not using "mysql_query_with_error_report" because we may have not
@@ -2380,7 +2407,7 @@ static uint dump_routines_for_db(char *db)
23802407
query_buff);
23812408
print_comment(sql_file, 1,
23822409
"-- does %s have permissions on mysql.proc?\n\n",
2383-
current_user);
2410+
fix_identifier_with_newline(current_user));
23842411
maybe_die(EX_MYSQLERR,"%s has insufficent privileges to %s!", current_user, query_buff);
23852412
}
23862413
else if (strlen(row[2]))
@@ -2593,12 +2620,12 @@ static uint get_table_structure(char *table, char *db, char *table_type,
25932620

25942621
if (strcmp (table_type, "VIEW") == 0) /* view */
25952622
print_comment(sql_file, 0,
2596-
"\n--\n-- Temporary view structure for view %s\n--\n\n",
2597-
result_table);
2623+
"\n--\n-- Temporary table structure for view %s\n--\n\n",
2624+
fix_identifier_with_newline(result_table));
25982625
else
25992626
print_comment(sql_file, 0,
26002627
"\n--\n-- Table structure for table %s\n--\n\n",
2601-
result_table);
2628+
fix_identifier_with_newline(result_table));
26022629

26032630
if (opt_drop)
26042631
{
@@ -2833,7 +2860,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
28332860

28342861
print_comment(sql_file, 0,
28352862
"\n--\n-- Table structure for table %s\n--\n\n",
2836-
result_table);
2863+
fix_identifier_with_newline(result_table));
28372864
if (opt_drop)
28382865
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", result_table);
28392866
if (!opt_xml)
@@ -3531,21 +3558,23 @@ static void dump_table(char *table, char *db)
35313558
{
35323559
print_comment(md_result_file, 0,
35333560
"\n--\n-- Dumping data for table %s\n--\n",
3534-
result_table);
3561+
fix_identifier_with_newline(result_table));
35353562

35363563
dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ * FROM ");
35373564
dynstr_append_checked(&query_string, result_table);
35383565

35393566
if (where)
35403567
{
3541-
print_comment(md_result_file, 0, "-- WHERE: %s\n", where);
3568+
print_comment(md_result_file, 0, "-- WHERE: %s\n",
3569+
fix_identifier_with_newline(where));
35423570

35433571
dynstr_append_checked(&query_string, " WHERE ");
35443572
dynstr_append_checked(&query_string, where);
35453573
}
35463574
if (order_by)
35473575
{
3548-
print_comment(md_result_file, 0, "-- ORDER BY: %s\n", order_by);
3576+
print_comment(md_result_file, 0, "-- ORDER BY: %s\n",
3577+
fix_identifier_with_newline(order_by));
35493578

35503579
dynstr_append_checked(&query_string, " ORDER BY ");
35513580
dynstr_append_checked(&query_string, order_by);
@@ -4371,7 +4400,8 @@ static int init_dumping(char *database, int init_func(char*))
43714400
char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
43724401

43734402
print_comment(md_result_file, 0,
4374-
"\n--\n-- Current Database: %s\n--\n", qdatabase);
4403+
"\n--\n-- Current Database: %s\n--\n",
4404+
fix_identifier_with_newline(qdatabase));
43754405

43764406
/* Call the view or table specific function */
43774407
init_func(qdatabase);
@@ -5597,7 +5627,7 @@ static my_bool get_view_structure(char *table, char* db)
55975627

55985628
print_comment(sql_file, 0,
55995629
"\n--\n-- Final view structure for view %s\n--\n\n",
5600-
result_table);
5630+
fix_identifier_with_newline(result_table));
56015631

56025632
verbose_msg("-- Dropping the temporary view structure created\n");
56035633
fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n", opt_quoted_table);

mysql-test/r/mysqldump.result

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5432,3 +5432,66 @@ a
54325432
DROP TABLE t1;
54335433
DROP TABLE t2;
54345434
DROP DATABASE db_20772273;
5435+
#
5436+
# Bug #25717383: MYSQLDUMP MAY EXECUTE ANY ARBITRARY QUERY
5437+
#
5438+
CREATE DATABASE bug25717383;
5439+
use bug25717383;
5440+
CREATE TABLE `tab
5441+
one` (a int);
5442+
CREATE VIEW `view
5443+
one` as SELECT * FROM `tab
5444+
one`;
5445+
CREATE PROCEDURE `proc
5446+
one`() SELECT * from `tab
5447+
one`;
5448+
CREATE TEMPORARY TABLE `temp
5449+
one` (id INT);
5450+
CREATE TRIGGER `trig
5451+
one` BEFORE INSERT ON `tab
5452+
one` FOR EACH ROW SET NEW.a = 1;
5453+
CREATE EVENT `event
5454+
one` ON SCHEDULE AT '2030-01-01 00:00:00' DO SET @a=5;
5455+
SHOW TABLES FROM bug25717383;
5456+
Tables_in_bug25717383
5457+
tab
5458+
one
5459+
view
5460+
one
5461+
SHOW TRIGGERS FROM bug25717383;
5462+
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
5463+
trig
5464+
one INSERT tab
5465+
one SET NEW.a = 1 BEFORE NULL root@localhost utf8 utf8_general_ci latin1_swedish_ci
5466+
SHOW EVENTS FROM bug25717383;
5467+
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
5468+
bug25717383 event
5469+
one root@localhost SYSTEM ONE TIME # NULL NULL NULL NULL ENABLED 1 utf8 utf8_general_ci latin1_swedish_ci
5470+
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
5471+
WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE'
5472+
ORDER BY ROUTINE_NAME;
5473+
ROUTINE_NAME
5474+
proc
5475+
one
5476+
SHOW TABLES FROM bug25717383;
5477+
Tables_in_bug25717383
5478+
tab
5479+
one
5480+
view
5481+
one
5482+
SHOW TRIGGERS FROM bug25717383;
5483+
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
5484+
trig
5485+
one INSERT tab
5486+
one SET NEW.a = 1 BEFORE NULL root@localhost utf8 utf8_general_ci latin1_swedish_ci
5487+
SHOW EVENTS FROM bug25717383;
5488+
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
5489+
bug25717383 event
5490+
one root@localhost SYSTEM ONE TIME # NULL NULL NULL NULL ENABLED 1 utf8 utf8_general_ci latin1_swedish_ci
5491+
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
5492+
WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE'
5493+
ORDER BY ROUTINE_NAME;
5494+
ROUTINE_NAME
5495+
proc
5496+
one
5497+
DROP DATABASE bug25717383;

mysql-test/t/mysqldump.test

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,3 +2523,53 @@ SELECT * FROM t2;
25232523
DROP TABLE t1;
25242524
DROP TABLE t2;
25252525
DROP DATABASE db_20772273;
2526+
2527+
--echo #
2528+
--echo # Bug #25717383: MYSQLDUMP MAY EXECUTE ANY ARBITRARY QUERY
2529+
--echo #
2530+
2531+
2532+
CREATE DATABASE bug25717383;
2533+
use bug25717383;
2534+
2535+
CREATE TABLE `tab
2536+
one` (a int);
2537+
CREATE VIEW `view
2538+
one` as SELECT * FROM `tab
2539+
one`;
2540+
2541+
CREATE PROCEDURE `proc
2542+
one`() SELECT * from `tab
2543+
one`;
2544+
2545+
CREATE TEMPORARY TABLE `temp
2546+
one` (id INT);
2547+
2548+
CREATE TRIGGER `trig
2549+
one` BEFORE INSERT ON `tab
2550+
one` FOR EACH ROW SET NEW.a = 1;
2551+
2552+
CREATE EVENT `event
2553+
one` ON SCHEDULE AT '2030-01-01 00:00:00' DO SET @a=5;
2554+
2555+
SHOW TABLES FROM bug25717383;
2556+
SHOW TRIGGERS FROM bug25717383;
2557+
--replace_column 6 #
2558+
SHOW EVENTS FROM bug25717383;
2559+
2560+
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
2561+
WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE'
2562+
ORDER BY ROUTINE_NAME;
2563+
2564+
--exec $MYSQL_DUMP --triggers --events --routines --add-drop-database --databases bug25717383 > $MYSQLTEST_VARDIR/tmp/bug25717383.sql
2565+
2566+
SHOW TABLES FROM bug25717383;
2567+
SHOW TRIGGERS FROM bug25717383;
2568+
--replace_column 6 #
2569+
SHOW EVENTS FROM bug25717383;
2570+
2571+
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
2572+
WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE'
2573+
ORDER BY ROUTINE_NAME;
2574+
2575+
DROP DATABASE bug25717383;

0 commit comments

Comments
 (0)