diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-08-09 20:20:47 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-08-09 20:20:47 +0000 |
| commit | b06c90764526ccf291011ecbbcab49ae9729f65a (patch) | |
| tree | fa8c61fb9f807e58fb098b9d565a698f0fde9fde /src/port/path.c | |
| parent | 35f539b481b5524bd331cb7b75df848da51b43e5 (diff) | |
| download | postgresql-b06c90764526ccf291011ecbbcab49ae9729f65a.tar.gz | |
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.
Diffstat (limited to 'src/port/path.c')
| -rw-r--r-- | src/port/path.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/port/path.c b/src/port/path.c index 1e45a8f3e2..040c8a6eb7 100644 --- a/src/port/path.c +++ b/src/port/path.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/path.c,v 1.26 2004/08/01 06:56:39 momjian Exp $ + * $PostgreSQL: pgsql/src/port/path.c,v 1.27 2004/08/09 20:20:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -116,11 +116,33 @@ canonicalize_path(char *path) #endif /* - * Removing the trailing slash on a path means we never get - * ugly double slashes. Don't remove a leading slash, though. - * Also, Win32 can't stat() a directory with a trailing slash. + * Removing the trailing slash on a path means we never get ugly double + * slashes. Also, Win32 can't stat() a directory with a trailing slash. + * Don't remove a leading slash, though. */ trim_trailing_separator(path); + + /* + * Remove any trailing uses of "." or "..", too. + */ + for (;;) + { + int len = strlen(path); + + if (len >= 2 && strcmp(path + len - 2, "/.") == 0) + { + trim_directory(path); + trim_trailing_separator(path); + } + else if (len >= 3 && strcmp(path + len - 3, "/..") == 0) + { + trim_directory(path); + trim_directory(path); + trim_trailing_separator(path); + } + else + break; + } } @@ -444,7 +466,7 @@ trim_trailing_separator(char *path) #ifdef WIN32 /* * Skip over network and drive specifiers for win32. - * Set 'path' to point to the last character to keep. + * Set 'path' to point to the last character we must keep. */ if (strlen(path) >= 2) { |
