1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

MDEV-39118: test_if_hard_path crashes on recursively resolving $HOME

Problem:
  When `$HOME` is set to `~/` (or any string starting with `~/`), the
  `home_dir` is initialized to that value. When `test_if_hard_path` is
  called on a path starting with `~/`, it replaces the `~/` prefix by
  recursively calling `test_if_hard_path(home_dir)` leading to infinite
  recursion and a crash.

Fix:
  Add a check in `test_if_hard_path` to see if `home_dir` itself begins
  with `~/`. If it does, skip the recursive call to prevent the
  infinite loop.
This commit is contained in:
Raghunandan Bhat
2026-04-15 16:39:47 +05:30
committed by Raghunandan Bhat
parent 7f8dc5004d
commit 86a15de7c0
7 changed files with 39 additions and 1 deletions

View File

@@ -0,0 +1,4 @@
!include include/default_my.cnf
[ENV]
HOME=~\

View File

@@ -0,0 +1,6 @@
#
# MDEV-39118: test_if_hard_path() crashes on recursively resolving $HOME
#
create table t (c int) engine=MyISAM data directory="~\\foo\\bar";
ERROR 42000: Incorrect table name '~\foo\bar'
# End of 10.11 tests

View File

@@ -0,0 +1,9 @@
--source include/windows.inc
--echo #
--echo # MDEV-39118: test_if_hard_path() crashes on recursively resolving \$HOME
--echo #
--error ER_WRONG_TABLE_NAME
create table t (c int) engine=MyISAM data directory="~\\foo\\bar";
--echo # End of 10.11 tests

View File

@@ -0,0 +1,4 @@
!include include/default_my.cnf
[ENV]
HOME=~/

View File

@@ -0,0 +1,6 @@
#
# MDEV-39118: test_if_hard_path() crashes on recursively resolving $HOME
#
create table t (c int) engine=MyISAM data directory="~/foo/bar";
ERROR 42000: Incorrect table name '~/foo/bar'
# End of 10.11 tests

View File

@@ -0,0 +1,9 @@
--source include/not_windows.inc
--echo #
--echo # MDEV-39118: test_if_hard_path() crashes on recursively resolving \$HOME
--echo #
--error ER_WRONG_TABLE_NAME
create table t (c int) engine=MyISAM data directory="~/foo/bar";
--echo # End of 10.11 tests

View File

@@ -132,7 +132,7 @@ int my_setwd(const char *dir, myf MyFlags)
int test_if_hard_path(register const char *dir_name)
{
if (dir_name[0] == FN_HOMELIB && dir_name[1] == FN_LIBCHAR)
return (home_dir != NullS && test_if_hard_path(home_dir));
return (home_dir != NullS && home_dir != dir_name && test_if_hard_path(home_dir));
if (dir_name[0] == FN_LIBCHAR)
return (TRUE);
#ifdef FN_DEVCHAR