mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
Properly handle Win32 paths of 'E:abc', which can be either absolute or
relative, by creating a function path_is_relative_and_below_cwd() to check for specific requirements. It is unclear if this fixes a security problem or not but the new code is more robust.
This commit is contained in:
@ -73,32 +73,30 @@ convert_and_check_filename(text *arg, bool logAllowed)
|
||||
|
||||
canonicalize_path(filename); /* filename can change length here */
|
||||
|
||||
/* Disallow ".." in the path */
|
||||
if (path_contains_parent_reference(filename))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
(errmsg("reference to parent directory (\"..\") not allowed"))));
|
||||
|
||||
if (is_absolute_path(filename))
|
||||
{
|
||||
/* Allow absolute references within DataDir */
|
||||
if (path_is_prefix_of_path(DataDir, filename))
|
||||
return filename;
|
||||
/* The log directory might be outside our datadir, but allow it */
|
||||
if (logAllowed &&
|
||||
is_absolute_path(Log_directory) &&
|
||||
path_is_prefix_of_path(Log_directory, filename))
|
||||
return filename;
|
||||
|
||||
ereport(ERROR,
|
||||
/* Disallow '/a/b/data/..' */
|
||||
if (path_contains_parent_reference(filename))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
(errmsg("reference to parent directory (\"..\") not allowed"))));
|
||||
/*
|
||||
* Allow absolute paths if within DataDir or Log_directory, even
|
||||
* though Log_directory might be outside DataDir.
|
||||
*/
|
||||
if (!path_is_prefix_of_path(DataDir, filename) &&
|
||||
(!logAllowed || !is_absolute_path(Log_directory) ||
|
||||
!path_is_prefix_of_path(Log_directory, filename)))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
(errmsg("absolute path not allowed"))));
|
||||
return NULL; /* keep compiler quiet */
|
||||
}
|
||||
else
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
else if (!path_is_relative_and_below_cwd(filename))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
(errmsg("path must be in or below the current directory"))));
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user