Skip to content

Commit 77c4c0f

Browse files
committed
MDEV-34203 Sandbox mode \- is not compatible with --binary-mode
"Process" sandbox short command put by masqldump to avoid an error.
1 parent d9d0e8f commit 77c4c0f

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

client/mysql.cc

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,8 @@ inline int get_command_index(char cmd_char)
11171117

11181118
static int delimiter_index= -1;
11191119
static int charset_index= -1;
1120+
static int sandbox_index= -1;
1121+
11201122
static bool real_binary_mode= FALSE;
11211123

11221124

@@ -1127,7 +1129,8 @@ int main(int argc,char *argv[])
11271129
MY_INIT(argv[0]);
11281130
DBUG_ENTER("main");
11291131
DBUG_PROCESS(argv[0]);
1130-
1132+
1133+
sandbox_index= get_command_index('-');
11311134
charset_index= get_command_index('C');
11321135
delimiter_index= get_command_index('d');
11331136
delimiter_str= delimiter;
@@ -2234,8 +2237,9 @@ static int read_and_execute(bool interactive)
22342237

22352238
/**
22362239
It checks if the input is a short form command. It returns the command's
2237-
pointer if a command is found, else return NULL. Note that if binary-mode
2238-
is set, then only \C is searched for.
2240+
pointer if a command is found, else return NULL.
2241+
2242+
Note that if binary-mode is set, then only \C and \- are searched for.
22392243
22402244
@param cmd_char A character of one byte.
22412245
@@ -2250,13 +2254,23 @@ static COMMANDS *find_command(char cmd_char)
22502254
int index= -1;
22512255

22522256
/*
2253-
In binary-mode, we disallow all mysql commands except '\C'
2254-
and DELIMITER.
2257+
In binary-mode, we disallow all client commands except '\C',
2258+
DELIMITER (see long comand finding find_command(char *))
2259+
and '\-' (sandbox, see following comment).
22552260
*/
22562261
if (real_binary_mode)
22572262
{
22582263
if (cmd_char == 'C')
22592264
index= charset_index;
2265+
/*
2266+
binary-mode enforces stricter controls compared to sandbox mode.
2267+
Whether sandbox mode is enabled or not is irrelevant when
2268+
binary-mode is active.
2269+
The only purpose of processing sandbox mode here is to avoid error
2270+
messages on files made by mysqldump.
2271+
*/
2272+
else if (cmd_char == '-')
2273+
index= sandbox_index;
22602274
}
22612275
else
22622276
index= get_command_index(cmd_char);
@@ -2312,6 +2326,12 @@ static COMMANDS *find_command(char *name)
23122326
len= (uint) strlen(name);
23132327

23142328
int index= -1;
2329+
/*
2330+
In binary-mode, we disallow all client commands except DELIMITER
2331+
and short commands '\C' and '\-' (see short command finding
2332+
find_command(char)).
2333+
*/
2334+
23152335
if (real_binary_mode)
23162336
{
23172337
if (is_delimiter_command(name, len))

mysql-test/main/mysql.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,15 @@ tee
658658
source
659659
^^^
660660
3
661+
#
662+
# MDEV-34203: Sandbox mode \- is not compatible with --binary-mode
663+
#
664+
create table t1 (a int);
665+
drop table t1;
666+
show create table t1;
667+
Table Create Table
668+
t1 CREATE TABLE `t1` (
669+
`a` int(11) DEFAULT NULL
670+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
671+
drop table t1;
661672
# End of 10.5 tests

mysql-test/main/mysql.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,4 +757,20 @@ source $MYSQL_TMP_DIR/mysql_in;" $MYSQL_TMP_DIR/mysql_in2;
757757
--remove_file $MYSQL_TMP_DIR/mysql_in
758758
--remove_file $MYSQL_TMP_DIR/mysql_in2
759759

760+
--echo #
761+
--echo # MDEV-34203: Sandbox mode \- is not compatible with --binary-mode
762+
--echo #
763+
764+
create table t1 (a int);
765+
766+
--exec $MYSQL_DUMP test t1 > $MYSQLTEST_VARDIR/tmp/MDEV-34203.sql
767+
768+
drop table t1;
769+
770+
--exec $MYSQL --binary-mode test 2>&1 < $MYSQLTEST_VARDIR/tmp/MDEV-34203.sql
771+
772+
show create table t1;
773+
drop table t1;
774+
--remove_file $MYSQLTEST_VARDIR/tmp/MDEV-34203.sql
775+
760776
--echo # End of 10.5 tests

0 commit comments

Comments
 (0)