Skip to content

Commit 4826e15

Browse files
Bharathy SatishHery Ramilison
Bharathy Satish
authored and
Hery Ramilison
committed
Merge branch 'mysql-5.6' into mysql-5.7
(cherry picked from commit f1e6ace429bb95b417e46fa7e5104790dbca5412)
1 parent 752acb1 commit 4826e15

File tree

3 files changed

+159
-14
lines changed

3 files changed

+159
-14
lines changed

client/mysqldump.c

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -591,6 +591,7 @@ static int dump_tablespaces_for_databases(char** databases);
591591
static int dump_tablespaces(char* ts_where);
592592
static void print_comment(FILE *sql_file, my_bool is_error, const char *format,
593593
...);
594+
static const char* fix_identifier_with_newline(char*);
594595

595596

596597
/*
@@ -705,7 +706,7 @@ static void write_header(FILE *sql_file, char *db_name)
705706
MACHINE_TYPE);
706707
print_comment(sql_file, 0, "-- Host: %s Database: %s\n",
707708
current_host ? current_host : "localhost",
708-
db_name ? db_name : "");
709+
db_name ? fix_identifier_with_newline(db_name) : "");
709710
print_comment(sql_file, 0,
710711
"-- ------------------------------------------------------\n"
711712
);
@@ -2150,6 +2151,30 @@ static void print_comment(FILE *sql_file, my_bool is_error, const char *format,
21502151
print_xml_comment(sql_file, strlen(comment_buff), comment_buff);
21512152
}
21522153

2154+
/*
2155+
This function accepts object names and prefixes -- wherever \n
2156+
character is found.
2157+
2158+
@param[in] object_name
2159+
2160+
@return
2161+
@retval fixed object name.
2162+
*/
2163+
2164+
static const char* fix_identifier_with_newline(char* object_name)
2165+
{
2166+
static char buff[COMMENT_LENGTH]= {0};
2167+
char *ptr= buff;
2168+
memset(buff, 0, 255);
2169+
while(*object_name)
2170+
{
2171+
*ptr++ = *object_name;
2172+
if (*object_name == '\n')
2173+
ptr= my_stpcpy(ptr, "-- ");
2174+
object_name++;
2175+
}
2176+
return buff;
2177+
}
21532178

21542179
/*
21552180
create_delimiter
@@ -2218,7 +2243,8 @@ static uint dump_events_for_db(char *db)
22182243
db, (ulong)strlen(db), '\'');
22192244
/* nice comments */
22202245
print_comment(sql_file, 0,
2221-
"\n--\n-- Dumping events for database '%s'\n--\n", db);
2246+
"\n--\n-- Dumping events for database '%s'\n--\n",
2247+
fix_identifier_with_newline(db));
22222248

22232249
/*
22242250
not using "mysql_query_with_error_report" because we may have not
@@ -2431,7 +2457,8 @@ static uint dump_routines_for_db(char *db)
24312457
db, (ulong)strlen(db), '\'');
24322458
/* nice comments */
24332459
print_comment(sql_file, 0,
2434-
"\n--\n-- Dumping routines for database '%s'\n--\n", db);
2460+
"\n--\n-- Dumping routines for database '%s'\n--\n",
2461+
fix_identifier_with_newline(db));
24352462

24362463
/*
24372464
not using "mysql_query_with_error_report" because we may have not
@@ -2490,7 +2517,7 @@ static uint dump_routines_for_db(char *db)
24902517
query_buff);
24912518
print_comment(sql_file, 1,
24922519
"-- does %s have permissions on mysql.proc?\n\n",
2493-
current_user);
2520+
fix_identifier_with_newline(current_user));
24942521
maybe_die(EX_MYSQLERR,"%s has insufficent privileges to %s!", current_user, query_buff);
24952522
}
24962523
else if (strlen(row[2]))
@@ -2696,12 +2723,12 @@ static uint get_table_structure(char *table, char *db, char *table_type,
26962723

26972724
if (strcmp (table_type, "VIEW") == 0) /* view */
26982725
print_comment(sql_file, 0,
2699-
"\n--\n-- Temporary view structure for view %s\n--\n\n",
2700-
result_table);
2726+
"\n--\n-- Temporary table structure for view %s\n--\n\n",
2727+
fix_identifier_with_newline(result_table));
27012728
else
27022729
print_comment(sql_file, 0,
27032730
"\n--\n-- Table structure for table %s\n--\n\n",
2704-
result_table);
2731+
fix_identifier_with_newline(result_table));
27052732

27062733
if (opt_drop)
27072734
{
@@ -2988,7 +3015,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
29883015

29893016
print_comment(sql_file, 0,
29903017
"\n--\n-- Table structure for table %s\n--\n\n",
2991-
result_table);
3018+
fix_identifier_with_newline(result_table));
29923019
if (opt_drop)
29933020
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", result_table);
29943021
if (!opt_xml)
@@ -3704,14 +3731,15 @@ static void dump_table(char *table, char *db)
37043731
{
37053732
print_comment(md_result_file, 0,
37063733
"\n--\n-- Dumping data for table %s\n--\n",
3707-
result_table);
3734+
fix_identifier_with_newline(result_table));
37083735

37093736
dynstr_append_checked(&query_string, "SELECT /*!40001 SQL_NO_CACHE */ * FROM ");
37103737
dynstr_append_checked(&query_string, result_table);
37113738

37123739
if (where)
37133740
{
3714-
print_comment(md_result_file, 0, "-- WHERE: %s\n", where);
3741+
print_comment(md_result_file, 0, "-- WHERE: %s\n",
3742+
fix_identifier_with_newline(where));
37153743

37163744
dynstr_append_checked(&query_string, " WHERE ");
37173745
dynstr_append_checked(&query_string, where);
@@ -3728,7 +3756,8 @@ static void dump_table(char *table, char *db)
37283756
}
37293757
if (order_by)
37303758
{
3731-
print_comment(md_result_file, 0, "-- ORDER BY: %s\n", order_by);
3759+
print_comment(md_result_file, 0, "-- ORDER BY: %s\n",
3760+
fix_identifier_with_newline(order_by));
37323761

37333762
dynstr_append_checked(&query_string, " ORDER BY ");
37343763
dynstr_append_checked(&query_string, order_by);
@@ -4572,7 +4601,8 @@ static int init_dumping(char *database, int init_func(char*))
45724601
char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
45734602

45744603
print_comment(md_result_file, 0,
4575-
"\n--\n-- Current Database: %s\n--\n", qdatabase);
4604+
"\n--\n-- Current Database: %s\n--\n",
4605+
fix_identifier_with_newline(qdatabase));
45764606

45774607
/* Call the view or table specific function */
45784608
init_func(qdatabase);
@@ -5802,7 +5832,7 @@ static my_bool get_view_structure(char *table, char* db)
58025832

58035833
print_comment(sql_file, 0,
58045834
"\n--\n-- Final view structure for view %s\n--\n\n",
5805-
result_table);
5835+
fix_identifier_with_newline(result_table));
58065836

58075837
verbose_msg("-- Dropping the temporary view structure created\n");
58085838
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
@@ -5526,3 +5526,66 @@ COUNT(*)
55265526
SELECT COUNT(*) FROM mysql.proc WHERE db = 'sys';
55275527
COUNT(*)
55285528
48
5529+
#
5530+
# Bug #25717383: MYSQLDUMP MAY EXECUTE ANY ARBITRARY QUERY
5531+
#
5532+
CREATE DATABASE bug25717383;
5533+
use bug25717383;
5534+
CREATE TABLE `tab
5535+
one` (a int);
5536+
CREATE VIEW `view
5537+
one` as SELECT * FROM `tab
5538+
one`;
5539+
CREATE PROCEDURE `proc
5540+
one`() SELECT * from `tab
5541+
one`;
5542+
CREATE TEMPORARY TABLE `temp
5543+
one` (id INT);
5544+
CREATE TRIGGER `trig
5545+
one` BEFORE INSERT ON `tab
5546+
one` FOR EACH ROW SET NEW.a = 1;
5547+
CREATE EVENT `event
5548+
one` ON SCHEDULE AT '2030-01-01 00:00:00' DO SET @a=5;
5549+
SHOW TABLES FROM bug25717383;
5550+
Tables_in_bug25717383
5551+
tab
5552+
one
5553+
view
5554+
one
5555+
SHOW TRIGGERS FROM bug25717383;
5556+
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
5557+
trig
5558+
one INSERT tab
5559+
one SET NEW.a = 1 BEFORE # root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
5560+
SHOW EVENTS FROM bug25717383;
5561+
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
5562+
bug25717383 event
5563+
one root@localhost SYSTEM ONE TIME # NULL NULL NULL NULL ENABLED 1 latin1 latin1_swedish_ci latin1_swedish_ci
5564+
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
5565+
WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE'
5566+
ORDER BY ROUTINE_NAME;
5567+
ROUTINE_NAME
5568+
proc
5569+
one
5570+
SHOW TABLES FROM bug25717383;
5571+
Tables_in_bug25717383
5572+
tab
5573+
one
5574+
view
5575+
one
5576+
SHOW TRIGGERS FROM bug25717383;
5577+
Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
5578+
trig
5579+
one INSERT tab
5580+
one SET NEW.a = 1 BEFORE # root@localhost latin1 latin1_swedish_ci latin1_swedish_ci
5581+
SHOW EVENTS FROM bug25717383;
5582+
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
5583+
bug25717383 event
5584+
one root@localhost SYSTEM ONE TIME # NULL NULL NULL NULL ENABLED 1 latin1 latin1_swedish_ci latin1_swedish_ci
5585+
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
5586+
WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE'
5587+
ORDER BY ROUTINE_NAME;
5588+
ROUTINE_NAME
5589+
proc
5590+
one
5591+
DROP DATABASE bug25717383;

mysql-test/t/mysqldump.test

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,3 +2645,55 @@ SELECT COUNT(*) FROM mysql.proc WHERE db = 'sys';
26452645
--remove_file $MYSQLTEST_VARDIR/tmp/bug21549860.sql
26462646
--remove_file $MYSQLTEST_VARDIR/tmp/mysql.proc.sql
26472647
--remove_file $MYSQLTEST_VARDIR/tmp/sys.sql
2648+
2649+
--echo #
2650+
--echo # Bug #25717383: MYSQLDUMP MAY EXECUTE ANY ARBITRARY QUERY
2651+
--echo #
2652+
2653+
2654+
CREATE DATABASE bug25717383;
2655+
use bug25717383;
2656+
2657+
CREATE TABLE `tab
2658+
one` (a int);
2659+
CREATE VIEW `view
2660+
one` as SELECT * FROM `tab
2661+
one`;
2662+
2663+
CREATE PROCEDURE `proc
2664+
one`() SELECT * from `tab
2665+
one`;
2666+
2667+
CREATE TEMPORARY TABLE `temp
2668+
one` (id INT);
2669+
2670+
CREATE TRIGGER `trig
2671+
one` BEFORE INSERT ON `tab
2672+
one` FOR EACH ROW SET NEW.a = 1;
2673+
2674+
CREATE EVENT `event
2675+
one` ON SCHEDULE AT '2030-01-01 00:00:00' DO SET @a=5;
2676+
2677+
SHOW TABLES FROM bug25717383;
2678+
--replace_column 6 #
2679+
SHOW TRIGGERS FROM bug25717383;
2680+
--replace_column 6 #
2681+
SHOW EVENTS FROM bug25717383;
2682+
2683+
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
2684+
WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE'
2685+
ORDER BY ROUTINE_NAME;
2686+
2687+
--exec $MYSQL_DUMP --triggers --events --routines --add-drop-database --databases bug25717383 > $MYSQLTEST_VARDIR/tmp/bug25717383.sql
2688+
2689+
SHOW TABLES FROM bug25717383;
2690+
--replace_column 6 #
2691+
SHOW TRIGGERS FROM bug25717383;
2692+
--replace_column 6 #
2693+
SHOW EVENTS FROM bug25717383;
2694+
2695+
SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
2696+
WHERE ROUTINE_SCHEMA='bug25717383' AND ROUTINE_TYPE= 'PROCEDURE'
2697+
ORDER BY ROUTINE_NAME;
2698+
2699+
DROP DATABASE bug25717383;

0 commit comments

Comments
 (0)