Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8aec77f

Browse files
committed
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.
1 parent 6b44d79 commit 8aec77f

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/backend/utils/adt/genfile.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Author: Andreas Pflug <pgadmin@pse-consulting.de>
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/genfile.c,v 1.5 2005/08/15 23:00:14 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/genfile.c,v 1.6 2005/08/29 19:39:39 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -41,7 +41,7 @@ typedef struct
4141
* Validate a path and convert to absolute form.
4242
*
4343
* Argument may be absolute or relative to the DataDir (but we only allow
44-
* absolute paths that match Log_directory).
44+
* absolute paths that match DataDir or Log_directory).
4545
*/
4646
static char *
4747
check_and_make_absolute(text *arg)
@@ -62,11 +62,12 @@ check_and_make_absolute(text *arg)
6262

6363
if (is_absolute_path(filename))
6464
{
65+
/* Allow absolute references within DataDir */
66+
if (path_is_prefix_of_path(DataDir, filename))
67+
return filename;
6568
/* The log directory might be outside our datadir, but allow it */
66-
if (is_absolute_path(Log_directory) &&
67-
strncmp(filename, Log_directory, strlen(Log_directory)) == 0 &&
68-
(filename[strlen(Log_directory)] == '/' ||
69-
filename[strlen(Log_directory)] == '\0'))
69+
if (is_absolute_path(Log_directory) &&
70+
path_is_prefix_of_path(Log_directory, filename))
7071
return filename;
7172

7273
ereport(ERROR,

src/include/port.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.81 2005/08/12 21:07:52 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.82 2005/08/29 19:39:39 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -33,6 +33,7 @@ extern void join_path_components(char *ret_path,
3333
extern void canonicalize_path(char *path);
3434
extern void make_native_path(char *path);
3535
extern bool path_contains_parent_reference(const char *path);
36+
extern bool path_is_prefix_of_path(const char *path1, const char *path2);
3637
extern const char *get_progname(const char *argv0);
3738
extern void get_share_path(const char *my_exec_path, char *ret_path);
3839
extern void get_etc_path(const char *my_exec_path, char *ret_path);

src/port/path.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/port/path.c,v 1.57 2005/08/12 21:07:53 tgl Exp $
11+
* $PostgreSQL: pgsql/src/port/path.c,v 1.58 2005/08/29 19:39:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -364,6 +364,22 @@ path_contains_parent_reference(const char *path)
364364
return false;
365365
}
366366

367+
/*
368+
* Detect whether path1 is a prefix of path2 (including equality).
369+
*
370+
* This is pretty trivial, but it seems better to export a function than
371+
* to export IS_DIR_SEP.
372+
*/
373+
bool
374+
path_is_prefix_of_path(const char *path1, const char *path2)
375+
{
376+
int path1_len = strlen(path1);
377+
378+
if (strncmp(path1, path2, path1_len) == 0 &&
379+
(IS_DIR_SEP(path2[path1_len]) || path2[path1_len] == '\0'))
380+
return true;
381+
return false;
382+
}
367383

368384
/*
369385
* Extracts the actual name of the program as called -

0 commit comments

Comments
 (0)