Re: Bug in canonicalize_path() - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Bug in canonicalize_path()
Date
Msg-id 200508120227.j7C2RO804420@candle.pha.pa.us
Whole thread Raw
In response to Re: Bug in canonicalize_path()  ("William ZHANG" <uniware@zedware.org>)
Responses Re: Bug in canonicalize_path()
List pgsql-patches
Yep, it is a bug on 8.0.X.  Are you suggesting a backpatch?  We can do
it.  Any objections?

---------------------------------------------------------------------------

William ZHANG wrote:
>
> What if we let the trailing "." or ".." as it is?
>
> On Windows, GetFullPathName() can canonicalize a given path.
>
> $ uname -a
> MINGW32_NT-5.0 DEV 1.0.10(0.46/3/2) 2003-10-11 10:14 i686 unknown
>
> $ cat path.c
>
> #include <windows.h>
>
> int
> main(void)
> {
>         CHAR Buf[1024];
>
>         GetFullPathName("C:\\Temp", 1024, Buf, NULL);
>         printf("%s\n", Buf);
>         GetFullPathName("C:\\Temp\\", 1024, Buf, NULL);
>         printf("%s\n", Buf);
>         GetFullPathName("C:\\Temp\\..\\", 1024, Buf, NULL);
>         printf("%s\n", Buf);
>         GetFullPathName("C:\\Temp\\..\\..", 1024, Buf, NULL);
>         printf("%s\n", Buf);
>
>         return 0;
> }
>
> $ gcc path.c
>
> $ ./a.exe
> C:\Temp
> C:\Temp\    # trailing "\" is not removed.
> C:\               #
> C:\               #  C:\Temp\..\..
>
> "Bruce Momjian" <pgman@candle.pha.pa.us> wrote
> news:200508110356.j7B3uqR14136@candle.pha.pa.us...
> > I found that in port/path.c::canonicalize_path, that if the path was
> > supplied as "/usr/local/bin/../.." we would return /usr/local/bin.  The
> > problem is then when we saw a trailing ".." we stripped it off and the
> > previous directory, but we never checked if the previous directory was
> > itself "..".
> >
> > Patch applied to suppress trimming of ".." if ".." is above it.  I tried
> > coding something that would handle "../.." but is started to look too
> > messy and not worth the effort.
> >
> > I don't see a need to backpatch this, but it could produce errors with
> > weird supplied paths.  Comments?
> >
> > --
> >   Bruce Momjian                        |  http://candle.pha.pa.us
> >   pgman@candle.pha.pa.us               |  (610) 359-1001
> >   +  If your life is a hard drive,     |  13 Roberts Road
> >   +  Christ can be your backup.        |  Newtown Square, Pennsylvania
> 19073
> >
>
>
> ----------------------------------------------------------------------------
> ----
>
>
> > ? pg_config_paths.h
> > Index: path.c
> > ===================================================================
> > RCS file: /cvsroot/pgsql/src/port/path.c,v
> > retrieving revision 1.51
> > diff -c -r1.51 path.c
> > *** path.c 26 Jan 2005 19:24:03 -0000 1.51
> > --- path.c 11 Aug 2005 03:52:06 -0000
> > ***************
> > *** 284,290 ****
> >
> >   if (len > 2 && strcmp(path + len - 2, "/.") == 0)
> >   trim_directory(path);
> > ! else if (len > 3 && strcmp(path + len - 3, "/..") == 0)
> >   {
> >   trim_directory(path);
> >   trim_directory(path); /* remove directory above */
> > --- 284,293 ----
> >
> >   if (len > 2 && strcmp(path + len - 2, "/.") == 0)
> >   trim_directory(path);
> > ! /* We can only deal with "/usr/local/..", not "/usr/local/../.." */
> > ! else if (len > 3 && strcmp(path + len - 3, "/..") == 0 &&
> > ! (len != 5 || strcmp(path, "../..") != 0) &&
> > ! (len < 6 || strcmp(path + len - 6, "/../..") != 0))
> >   {
> >   trim_directory(path);
> >   trim_directory(path); /* remove directory above */
> >
>
>
> ----------------------------------------------------------------------------
> ----
>
>
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: if posting/reading through Usenet, please send an appropriate
> >        subscribe-nomail command to majordomo@postgresql.org so that your
> >        message can get through to the mailing list cleanly
> >
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>        choose an index scan if your joining column's datatypes do not
>        match
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

pgsql-patches by date:

Previous
From: "William ZHANG"
Date:
Subject: Re: Bug in canonicalize_path()
Next
From: Tom Lane
Date:
Subject: Re: Bug in canonicalize_path()