1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +03:00

race-condition safe implementation of test_if_data_home_dir()

don't realpath() twice
This commit is contained in:
Sergei Golubchik
2017-02-20 19:53:12 +01:00
parent 93cb0246b8
commit 955f2f036d
3 changed files with 34 additions and 15 deletions

View File

@@ -7697,26 +7697,20 @@ bool check_ident_length(LEX_STRING *ident)
Check if path does not contain mysql data home directory
SYNOPSIS
test_if_data_home_dir()
dir directory
path_starts_from_data_home_dir()
dir directory, with all symlinks resolved
RETURN VALUES
0 ok
1 error ; Given path contains data directory
*/
C_MODE_START
extern "C" {
int test_if_data_home_dir(const char *dir)
int path_starts_from_data_home_dir(const char *path)
{
char path[FN_REFLEN];
int dir_len;
DBUG_ENTER("test_if_data_home_dir");
int dir_len= strlen(path);
DBUG_ENTER("path_starts_from_data_home_dir");
if (!dir)
DBUG_RETURN(0);
(void) fn_format(path, dir, "", "", MY_RETURN_REAL_PATH);
dir_len= strlen(path);
if (mysql_unpacked_real_data_home_len<= dir_len)
{
if (dir_len > mysql_unpacked_real_data_home_len &&
@@ -7744,7 +7738,31 @@ int test_if_data_home_dir(const char *dir)
DBUG_RETURN(0);
}
C_MODE_END
}
/*
Check if path does not contain mysql data home directory
SYNOPSIS
test_if_data_home_dir()
dir directory
RETURN VALUES
0 ok
1 error ; Given path contains data directory
*/
int test_if_data_home_dir(const char *dir)
{
char path[FN_REFLEN];
DBUG_ENTER("test_if_data_home_dir");
if (!dir)
DBUG_RETURN(0);
(void) fn_format(path, dir, "", "", MY_RETURN_REAL_PATH);
DBUG_RETURN(path_starts_from_data_home_dir(path));
}
/**