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

Commit b06c907

Browse files
committed
Path-mangling logic was failing to account for paths containing mentions
of '.' or '..'. Extend canonicalize_path() to trim off trailing occurrences of these things, and use it to fix up paths where needed (which I think is only after places where we trim the last path component, but maybe some others will turn up). Fixes Josh's complaint that './initdb' does not work.
1 parent 35f539b commit b06c907

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/bin/initdb/initdb.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Portions Copyright (c) 1994, Regents of the University of California
4040
* Portions taken from FreeBSD.
4141
*
42-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.46 2004/08/01 06:19:23 momjian Exp $
42+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.47 2004/08/09 20:20:47 tgl Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -2227,6 +2227,7 @@ main(int argc, char *argv[])
22272227
/* store binary directory */
22282228
strcpy(bin_path, backend_exec);
22292229
*last_dir_separator(bin_path) = '\0';
2230+
canonicalize_path(bin_path);
22302231

22312232
if (!share_path)
22322233
{

src/port/exec.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/port/exec.c,v 1.20 2004/08/09 03:12:38 momjian Exp $
10+
* $PostgreSQL: pgsql/src/port/exec.c,v 1.21 2004/08/09 20:20:46 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -433,6 +433,9 @@ find_other_exec(const char *argv0, const char *target,
433433

434434
/* Trim off program name and keep just directory */
435435
*last_dir_separator(retpath) = '\0';
436+
canonicalize_path(retpath);
437+
438+
/* Now append the other program's name */
436439
snprintf(retpath + strlen(retpath), MAXPGPATH - strlen(retpath),
437440
"/%s%s", target, EXE);
438441

src/port/path.c

+27-5
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.26 2004/08/01 06:56:39 momjian Exp $
11+
* $PostgreSQL: pgsql/src/port/path.c,v 1.27 2004/08/09 20:20:46 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -116,11 +116,33 @@ canonicalize_path(char *path)
116116
#endif
117117

118118
/*
119-
* Removing the trailing slash on a path means we never get
120-
* ugly double slashes. Don't remove a leading slash, though.
121-
* Also, Win32 can't stat() a directory with a trailing slash.
119+
* Removing the trailing slash on a path means we never get ugly double
120+
* slashes. Also, Win32 can't stat() a directory with a trailing slash.
121+
* Don't remove a leading slash, though.
122122
*/
123123
trim_trailing_separator(path);
124+
125+
/*
126+
* Remove any trailing uses of "." or "..", too.
127+
*/
128+
for (;;)
129+
{
130+
int len = strlen(path);
131+
132+
if (len >= 2 && strcmp(path + len - 2, "/.") == 0)
133+
{
134+
trim_directory(path);
135+
trim_trailing_separator(path);
136+
}
137+
else if (len >= 3 && strcmp(path + len - 3, "/..") == 0)
138+
{
139+
trim_directory(path);
140+
trim_directory(path);
141+
trim_trailing_separator(path);
142+
}
143+
else
144+
break;
145+
}
124146
}
125147

126148

@@ -444,7 +466,7 @@ trim_trailing_separator(char *path)
444466
#ifdef WIN32
445467
/*
446468
* Skip over network and drive specifiers for win32.
447-
* Set 'path' to point to the last character to keep.
469+
* Set 'path' to point to the last character we must keep.
448470
*/
449471
if (strlen(path) >= 2)
450472
{

0 commit comments

Comments
 (0)