Skip to content

Commit 955f2f0

Browse files
committed
race-condition safe implementation of test_if_data_home_dir()
don't realpath() twice
1 parent 93cb024 commit 955f2f0

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

sql/mysqld.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7267,7 +7267,7 @@ static int mysql_init_variables(void)
72677267
mysql_home[0]= pidfile_name[0]= log_error_file[0]= 0;
72687268
#if defined(HAVE_REALPATH) && !defined(HAVE_valgrind) && !defined(HAVE_BROKEN_REALPATH)
72697269
/* We can only test for sub paths if my_symlink.c is using realpath */
7270-
mysys_test_invalid_symlink= test_if_data_home_dir;
7270+
mysys_test_invalid_symlink= path_starts_from_data_home_dir;
72717271
#endif
72727272
opt_log= opt_slow_log= 0;
72737273
opt_bin_log= opt_bin_log_used= 0;

sql/sql_parse.cc

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7697,26 +7697,20 @@ bool check_ident_length(LEX_STRING *ident)
76977697
Check if path does not contain mysql data home directory
76987698
76997699
SYNOPSIS
7700-
test_if_data_home_dir()
7701-
dir directory
7700+
path_starts_from_data_home_dir()
7701+
dir directory, with all symlinks resolved
77027702
77037703
RETURN VALUES
77047704
0 ok
77057705
1 error ; Given path contains data directory
77067706
*/
7707-
C_MODE_START
7707+
extern "C" {
77087708

7709-
int test_if_data_home_dir(const char *dir)
7709+
int path_starts_from_data_home_dir(const char *path)
77107710
{
7711-
char path[FN_REFLEN];
7712-
int dir_len;
7713-
DBUG_ENTER("test_if_data_home_dir");
7711+
int dir_len= strlen(path);
7712+
DBUG_ENTER("path_starts_from_data_home_dir");
77147713

7715-
if (!dir)
7716-
DBUG_RETURN(0);
7717-
7718-
(void) fn_format(path, dir, "", "", MY_RETURN_REAL_PATH);
7719-
dir_len= strlen(path);
77207714
if (mysql_unpacked_real_data_home_len<= dir_len)
77217715
{
77227716
if (dir_len > mysql_unpacked_real_data_home_len &&
@@ -7744,7 +7738,31 @@ int test_if_data_home_dir(const char *dir)
77447738
DBUG_RETURN(0);
77457739
}
77467740

7747-
C_MODE_END
7741+
}
7742+
7743+
/*
7744+
Check if path does not contain mysql data home directory
7745+
7746+
SYNOPSIS
7747+
test_if_data_home_dir()
7748+
dir directory
7749+
7750+
RETURN VALUES
7751+
0 ok
7752+
1 error ; Given path contains data directory
7753+
*/
7754+
7755+
int test_if_data_home_dir(const char *dir)
7756+
{
7757+
char path[FN_REFLEN];
7758+
DBUG_ENTER("test_if_data_home_dir");
7759+
7760+
if (!dir)
7761+
DBUG_RETURN(0);
7762+
7763+
(void) fn_format(path, dir, "", "", MY_RETURN_REAL_PATH);
7764+
DBUG_RETURN(path_starts_from_data_home_dir(path));
7765+
}
77487766

77497767

77507768
/**

sql/sql_parse.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ enum enum_mysql_completiontype {
3333
COMMIT_RELEASE=-1, COMMIT=0, COMMIT_AND_CHAIN=6
3434
};
3535

36-
extern "C" int test_if_data_home_dir(const char *dir);
36+
extern "C" int path_starts_from_data_home_dir(const char *dir);
37+
int test_if_data_home_dir(const char *dir);
3738

3839
bool multi_update_precheck(THD *thd, TABLE_LIST *tables);
3940
bool multi_delete_precheck(THD *thd, TABLE_LIST *tables);

0 commit comments

Comments
 (0)