Commit c29e450e authored by Elena Stepanova's avatar Elena Stepanova

MDEV-4070 sys_vars.secure_file_priv fails sporadically if it's executed with --mem

The test created a file in location relative to the datadir
(a few levels above datadir).
The file was created by MariaDB server (via INTO OUTFILE), and
later removed by mysqltest (via remove_file). The problem is that
when the vardir is a symlink, MariaDB server and mysqltest can
resolve such paths differently. MariaDB server would return back
to where the symlink is located, while mysqltest would go above
the real directory. For example, if the test is run with --mem,
and /bld/5.5/mysql-test/var points at /dev/shm/var_auto_X, then
SELECT INTO OUTFILE created a file in /bld/5.5/mysql-test , but
remove_file would look for it in /dev/shm/.

The test is re-written so that all paths are resolved in perl,
the logic itself hasn't changed.
parent ceba41c0
......@@ -5,17 +5,39 @@ CREATE TABLE t1 (c1 VARCHAR(50));
INSERT INTO t1 VALUES ("one"),("two"),("three"),("four"),("five");
SHOW VARIABLES LIKE 'secure_file_priv';
--disable_query_log
# Atempt to create a file where we normally aren't allowed to create one.
#
# Doing this in a portable manner is difficult but we should be able to
# count on the depth of the directory hierarchy used. Three steps up from
# the datadir is the 'mysql_test' directory.
--let $PROTECTED_FILE=`SELECT concat(@@datadir,'/../../../bug50373.txt')`
--eval SELECT * FROM t1 INTO OUTFILE '$PROTECTED_FILE';
DELETE FROM t1;
--eval LOAD DATA INFILE '$PROTECTED_FILE' INTO TABLE t1;
SELECT * FROM t1;
--eval SELECT load_file('$PROTECTED_FILE') AS loaded_file;
# count on the directory hierarchy used. A step up from MYSQLTEST_VARDIR
# should definitely lead us to a "protected" directory,
# but at the same time should still be writable since MTR was able
# to create the vardir itself there.
# If we run tests normally, it will be mysql-test directory.
# If we run tests with --mem, it will be /dev/shm.
# If we run tests with --parallel, it will be mysql-test/var
# (because MYSQLTEST_VARDIR in this case is mysql-test/var/N).
--perl
use File::Basename;
my $protected_file= dirname($ENV{MYSQLTEST_VARDIR}).'/bug50373.txt';
open(FILE, ">", "$ENV{MYSQL_TMP_DIR}/bug50373.inc") or die;
print FILE "SELECT * FROM t1 INTO OUTFILE '".$protected_file."';\n";
print FILE "DELETE FROM t1;\n";
print FILE "LOAD DATA INFILE '".$protected_file."' INTO TABLE t1;\n";
print FILE "SELECT * FROM t1;\n";
print FILE "SELECT load_file('",$protected_file,"') AS loaded_file;\n";
close(FILE);
EOF
--source $MYSQL_TMP_DIR/bug50373.inc
--remove_file $MYSQL_TMP_DIR/bug50373.inc
--enable_query_log
remove_file $PROTECTED_FILE;
DROP TABLE t1;
--perl
use File::Basename;
unlink dirname($ENV{MYSQLTEST_VARDIR}).'/bug50373.txt';
EOF
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment