Skip to content

Commit 837f9fd

Browse files
committed
Merge branch 'mysql-8.0' into mysql-8.4
Change-Id: I7959dd50b72812030a997bae1931916ab842964a
2 parents d587cca + 2cc37b2 commit 837f9fd

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

client/mysql.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ static COMMANDS commands[] = {
431431
"Execute an SQL script file. Takes a file name as an argument."},
432432
{"status", 's', com_status, false,
433433
"Get status information from the server."},
434-
{"system", '!', com_shell, true, "Execute a system shell command."},
434+
{"system", '!', com_shell, true,
435+
"Execute a system shell command, if enabled"},
435436
{"tee", 'T', com_tee, true,
436437
"Set outfile [to_outfile]. Append everything into given outfile."},
437438
{"use", 'u', com_use, true,
@@ -1751,6 +1752,8 @@ void window_resize(int) {
17511752
}
17521753
#endif
17531754

1755+
static bool opt_system_command = true;
1756+
17541757
static struct my_option my_long_options[] = {
17551758
{"help", '?', "Display this help and exit.", nullptr, nullptr, nullptr,
17561759
GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
@@ -2083,6 +2086,10 @@ static struct my_option my_long_options[] = {
20832086
"Specifies factor for which registration needs to be done for.",
20842087
&opt_register_factor, &opt_register_factor, nullptr, GET_STR, REQUIRED_ARG,
20852088
0, 0, 0, nullptr, 0, nullptr},
2089+
{"system-command", 0,
2090+
"Enable (by default) or disable the system mysql command.",
2091+
&opt_system_command, &opt_system_command, nullptr, GET_BOOL, NO_ARG, 1, 0,
2092+
0, nullptr, 0, nullptr},
20862093
{nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0,
20872094
0, nullptr, 0, nullptr}};
20882095

@@ -4498,6 +4505,13 @@ static int com_shell(String *buffer [[maybe_unused]],
44984505
put_info("Usage: \\! shell-command", INFO_ERROR);
44994506
return -1;
45004507
}
4508+
4509+
if (!opt_system_command) {
4510+
return put_info(
4511+
"'system' command received, but the --system-command option is off. "
4512+
"Skipping.",
4513+
INFO_ERROR);
4514+
}
45014515
/*
45024516
The output of the shell command does not
45034517
get directed to the pager or the outfile

mysql-test/r/mysql.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,14 @@ include/assert_grep.inc [look for query_attributes in help]
572572
#
573573
# Success criteria: port number present in the error text
574574
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:99999' (XXX)
575+
#
576+
# Bug # 36377685: mysqldump blindly trusting SHOW CREATE TABLE leads to
577+
# arbitrary code execution.
578+
#
579+
# Test "system": Must return an error
580+
ERROR at line 1: 'system' command received, but the --system-command option is off. Skipping.
581+
# Test "!": Must return an error
582+
ERROR at line 1: 'system' command received, but the --system-command option is off. Skipping.
575583

576584
# Test support for dollar quoting
577585

mysql-test/t/mysql.test

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#
1+
2+
23
# Testing the MySQL command line client(mysql)
34
#
45

@@ -705,6 +706,19 @@ DROP USER bug21464621;
705706
--error 1
706707
--exec $MYSQL -h 127.0.0.1 -P 99999 2>&1
707708

709+
--echo #
710+
--echo # Bug # 36377685: mysqldump blindly trusting SHOW CREATE TABLE leads to
711+
--echo # arbitrary code execution.
712+
--echo #
713+
714+
--echo # Test "system": Must return an error
715+
--error 1
716+
--exec $MYSQL test --skip-system-command -e "system ls;" 2>&1
717+
718+
--echo # Test "!": Must return an error
719+
--error 1
720+
--exec $MYSQL test --skip-system-command -e "\\! ls" 2>&1
721+
708722
--echo
709723
--echo # Test support for dollar quoting
710724
--echo

0 commit comments

Comments
 (0)