Skip to content

Commit

Permalink
Make 'move_file' command more reliable in mysqltest
Browse files Browse the repository at this point in the history
The tests innodb.import_tablespace_race, innodn.restart, and innodb.innodb-wl5522 move
the tablespace file between the data directory and the tmp directory specified by
global environment variables. However this is risky because it's not unusual that the
set tmp directory (often under /tmp) is mounted on another disk partition or device,
and 'move_file' command may fail with "Errcode: 18 'Invalid cross-device link.'"

To stabilize mysqltest in the described scenario, and prevent such
behavior in the future, let make_file() check both from file path and to
file path and make sure they are either both under MYSQLTEST_VARDIR or
MYSQL_TMP_DIR.

All new code of the whole pull request, including one or several files that
are either new files or modified ones, are contributed under the BSD-new license.
I am contributing on behalf of my employer Amazon Web Services, Inc.
  • Loading branch information
lornacluo authored and vuvova committed Apr 3, 2023
1 parent 0a63439 commit da73db2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions client/mysqltest.cc
Expand Up @@ -3814,9 +3814,21 @@ void do_move_file(struct st_command *command)
sizeof(move_file_args)/sizeof(struct command_arg),
' ');

if (bad_path(ds_to_file.str))
DBUG_VOID_RETURN;
size_t from_plen = strlen(ds_from_file.str);
size_t to_plen = strlen(ds_to_file.str);
const char *vardir= getenv("MYSQLTEST_VARDIR");
const char *tmpdir= getenv("MYSQL_TMP_DIR");

if (!((is_sub_path(ds_from_file.str, from_plen, vardir) &&
is_sub_path(ds_to_file.str, to_plen, vardir)) ||
(is_sub_path(ds_from_file.str, from_plen, tmpdir) &&
is_sub_path(ds_to_file.str, to_plen, tmpdir)))) {
report_or_die("Paths '%s' and '%s' are not both under MYSQLTEST_VARDIR '%s'"
"or both under MYSQL_TMP_DIR '%s'",
ds_from_file, ds_to_file, vardir, tmpdir);
DBUG_VOID_RETURN;
}

DBUG_PRINT("info", ("Move %s to %s", ds_from_file.str, ds_to_file.str));
error= (my_rename(ds_from_file.str, ds_to_file.str,
MYF(disable_warnings ? 0 : MY_WME)) != 0);
Expand Down

0 comments on commit da73db2

Please sign in to comment.