]> granicus.if.org Git - postgresql/commitdiff
Path-mangling logic was failing to account for paths containing mentions
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 9 Aug 2004 20:20:47 +0000 (20:20 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 9 Aug 2004 20:20:47 +0000 (20:20 +0000)
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.

src/bin/initdb/initdb.c
src/port/exec.c
src/port/path.c

index 55b782004c45a7563a002dae64d2f1c7f97b45ff..de059e65bca3a84baabfcd6fa8712755b371c529 100644 (file)
@@ -39,7 +39,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  * Portions taken from FreeBSD.
  *
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.46 2004/08/01 06:19:23 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.47 2004/08/09 20:20:47 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2227,6 +2227,7 @@ main(int argc, char *argv[])
        /* store binary directory */
        strcpy(bin_path, backend_exec);
        *last_dir_separator(bin_path) = '\0';
+       canonicalize_path(bin_path);
 
        if (!share_path)
        {
index 440c63f0c52d062dfef80ab323bff8233186869f..85fec3ac478aac0fb34a71112064c463571f15ad 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/port/exec.c,v 1.20 2004/08/09 03:12:38 momjian Exp $
+ *       $PostgreSQL: pgsql/src/port/exec.c,v 1.21 2004/08/09 20:20:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -433,6 +433,9 @@ find_other_exec(const char *argv0, const char *target,
 
        /* Trim off program name and keep just directory */     
        *last_dir_separator(retpath) = '\0';
+       canonicalize_path(retpath);
+
+       /* Now append the other program's name */
        snprintf(retpath + strlen(retpath), MAXPGPATH - strlen(retpath),
                         "/%s%s", target, EXE);
 
index 1e45a8f3e2c69c7e37d7ec21fa5871b8852603b2..040c8a6eb721cec3104ea57d34f1c0cd26d9b18b 100644 (file)
@@ -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)
     {