Fix platform-specific test for path prefix-ness: move it into path.c where
it can be done right. Allow explicit use of absolute DataDir path. Per Dave Page.
This commit is contained in:
parent
6b44d796c7
commit
8aec77fb9f
@ -9,7 +9,7 @@
|
|||||||
* Author: Andreas Pflug <pgadmin@pse-consulting.de>
|
* Author: Andreas Pflug <pgadmin@pse-consulting.de>
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/genfile.c,v 1.5 2005/08/15 23:00:14 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/genfile.c,v 1.6 2005/08/29 19:39:39 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -41,7 +41,7 @@ typedef struct
|
|||||||
* Validate a path and convert to absolute form.
|
* Validate a path and convert to absolute form.
|
||||||
*
|
*
|
||||||
* Argument may be absolute or relative to the DataDir (but we only allow
|
* Argument may be absolute or relative to the DataDir (but we only allow
|
||||||
* absolute paths that match Log_directory).
|
* absolute paths that match DataDir or Log_directory).
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
check_and_make_absolute(text *arg)
|
check_and_make_absolute(text *arg)
|
||||||
@ -62,11 +62,12 @@ check_and_make_absolute(text *arg)
|
|||||||
|
|
||||||
if (is_absolute_path(filename))
|
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 */
|
/* The log directory might be outside our datadir, but allow it */
|
||||||
if (is_absolute_path(Log_directory) &&
|
if (is_absolute_path(Log_directory) &&
|
||||||
strncmp(filename, Log_directory, strlen(Log_directory)) == 0 &&
|
path_is_prefix_of_path(Log_directory, filename))
|
||||||
(filename[strlen(Log_directory)] == '/' ||
|
|
||||||
filename[strlen(Log_directory)] == '\0'))
|
|
||||||
return filename;
|
return filename;
|
||||||
|
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/port.h,v 1.81 2005/08/12 21:07:52 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/port.h,v 1.82 2005/08/29 19:39:39 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -33,6 +33,7 @@ extern void join_path_components(char *ret_path,
|
|||||||
extern void canonicalize_path(char *path);
|
extern void canonicalize_path(char *path);
|
||||||
extern void make_native_path(char *path);
|
extern void make_native_path(char *path);
|
||||||
extern bool path_contains_parent_reference(const char *path);
|
extern bool path_contains_parent_reference(const char *path);
|
||||||
|
extern bool path_is_prefix_of_path(const char *path1, const char *path2);
|
||||||
extern const char *get_progname(const char *argv0);
|
extern const char *get_progname(const char *argv0);
|
||||||
extern void get_share_path(const char *my_exec_path, char *ret_path);
|
extern void get_share_path(const char *my_exec_path, char *ret_path);
|
||||||
extern void get_etc_path(const char *my_exec_path, char *ret_path);
|
extern void get_etc_path(const char *my_exec_path, char *ret_path);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/port/path.c,v 1.57 2005/08/12 21:07:53 tgl Exp $
|
* $PostgreSQL: pgsql/src/port/path.c,v 1.58 2005/08/29 19:39:39 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -364,6 +364,22 @@ path_contains_parent_reference(const char *path)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Detect whether path1 is a prefix of path2 (including equality).
|
||||||
|
*
|
||||||
|
* This is pretty trivial, but it seems better to export a function than
|
||||||
|
* to export IS_DIR_SEP.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
path_is_prefix_of_path(const char *path1, const char *path2)
|
||||||
|
{
|
||||||
|
int path1_len = strlen(path1);
|
||||||
|
|
||||||
|
if (strncmp(path1, path2, path1_len) == 0 &&
|
||||||
|
(IS_DIR_SEP(path2[path1_len]) || path2[path1_len] == '\0'))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extracts the actual name of the program as called -
|
* Extracts the actual name of the program as called -
|
||||||
|
Loading…
x
Reference in New Issue
Block a user