Re: Bug in canonicalize_path()

From: "William ZHANG" <uniware(at)zedware(dot)org>
To: pgsql-patches(at)postgresql(dot)org
Subject: Re: Bug in canonicalize_path()
Date: 2005-08-12 02:20:32
Message-ID: ddh15v$28n7$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches


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(at)candle(dot)pha(dot)pa(dot)us> wrote
news:200508110356(dot)j7B3uqR14136(at)candle(dot)pha(dot)pa(dot)us(dot)(dot)(dot)
> 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(at)candle(dot)pha(dot)pa(dot)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(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2005-08-12 02:27:24 Re: Bug in canonicalize_path()
Previous Message Bruce Momjian 2005-08-12 02:11:42 Re: data on devel code perf dip