Skip to content

Commit 2cc37b2

Browse files
committed
WL#16482: mysqldump blindly trusting SHOW CREATE TABLE leads
to arbitrary code execution. The 8.0 version. Introduced a --[skip-]system-command command line/config file option for the mysql binary. Type: boolean Default: ON, can be turned off with --skip-system-command When --skip-system-command is specified and a system command or the abbreviated \! is specified, an error will be printed and the command won't be executed. Test case added. Change-Id: I46e8f3cc8e8a6aa37f8374c04a87177604cd124e
1 parent 81a7f6f commit 2cc37b2

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
@@ -400,7 +400,8 @@ static COMMANDS commands[] = {
400400
"Execute an SQL script file. Takes a file name as an argument."},
401401
{"status", 's', com_status, false,
402402
"Get status information from the server."},
403-
{"system", '!', com_shell, true, "Execute a system shell command."},
403+
{"system", '!', com_shell, true,
404+
"Execute a system shell command, if enabled"},
404405
{"tee", 'T', com_tee, true,
405406
"Set outfile [to_outfile]. Append everything into given outfile."},
406407
{"use", 'u', com_use, true,
@@ -1645,6 +1646,8 @@ void window_resize(int) {
16451646
}
16461647
#endif
16471648

1649+
static bool opt_system_command = true;
1650+
16481651
static struct my_option my_long_options[] = {
16491652
{"help", '?', "Display this help and exit.", nullptr, nullptr, nullptr,
16501653
GET_NO_ARG, NO_ARG, 0, 0, 0, nullptr, 0, nullptr},
@@ -1969,6 +1972,10 @@ static struct my_option my_long_options[] = {
19691972
&opt_oci_config_file, &opt_oci_config_file, nullptr, GET_STR, REQUIRED_ARG,
19701973
0, 0, 0, nullptr, 0, nullptr},
19711974
#include "authentication_kerberos_clientopt-longopts.h"
1975+
{"system-command", 0,
1976+
"Enable (by default) or disable the system mysql command.",
1977+
&opt_system_command, &opt_system_command, nullptr, GET_BOOL, NO_ARG, 1, 0,
1978+
0, nullptr, 0, nullptr},
19721979
{nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0,
19731980
0, nullptr, 0, nullptr}};
19741981

@@ -4128,6 +4135,13 @@ static int com_shell(String *buffer [[maybe_unused]],
41284135
put_info("Usage: \\! shell-command", INFO_ERROR);
41294136
return -1;
41304137
}
4138+
4139+
if (!opt_system_command) {
4140+
return put_info(
4141+
"'system' command received, but the --system-command option is off. "
4142+
"Skipping.",
4143+
INFO_ERROR);
4144+
}
41314145
/*
41324146
The output of the shell command does not
41334147
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
@@ -555,5 +555,13 @@ include/assert_grep.inc [look for query_attributes in help]
555555
#
556556
# Success criteria: port number present in the error text
557557
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:99999' (XXX)
558+
#
559+
# Bug # 36377685: mysqldump blindly trusting SHOW CREATE TABLE leads to
560+
# arbitrary code execution.
561+
#
562+
# Test "system": Must return an error
563+
ERROR at line 1: 'system' command received, but the --system-command option is off. Skipping.
564+
# Test "!": Must return an error
565+
ERROR at line 1: 'system' command received, but the --system-command option is off. Skipping.
558566

559567
End of tests

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

@@ -687,5 +688,18 @@ DROP USER bug21464621;
687688
--error 1
688689
--exec $MYSQL -h 127.0.0.1 -P 99999 2>&1
689690

691+
--echo #
692+
--echo # Bug # 36377685: mysqldump blindly trusting SHOW CREATE TABLE leads to
693+
--echo # arbitrary code execution.
694+
--echo #
695+
696+
--echo # Test "system": Must return an error
697+
--error 1
698+
--exec $MYSQL test --skip-system-command -e "system ls;" 2>&1
699+
700+
--echo # Test "!": Must return an error
701+
--error 1
702+
--exec $MYSQL test --skip-system-command -e "\\! ls" 2>&1
703+
690704
--echo
691705
--echo End of tests

0 commit comments

Comments
 (0)