Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb06c907

Browse files
committed
Path-mangling logic was failing to account for paths containing mentions
of '.' or '..'. Extend canonicalize_path() to trim off trailing occurrencesof these things, and use it to fix up paths where needed (which I think isonly after places where we trim the last path component, but maybe someothers will turn up). Fixes Josh's complaint that './initdb' does notwork.
1 parent35f539b commitb06c907

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 2 additions & 1 deletion
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

Lines changed: 4 additions & 1 deletion
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/0903:12:38 momjian Exp $
10+
* $PostgreSQL: pgsql/src/port/exec.c,v 1.21 2004/08/0920: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

Lines changed: 27 additions & 5 deletions
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 doubleslashes.Don'tremove aleading slash, though.
121-
*Also, Win32 can'tstat() adirectory with a trailingslash.
119+
*Removing the trailing slash on a path means we never get ugly double
120+
*slashes.Also, Win32 can'tstat() adirectory with a trailing slash.
121+
* Don'tremove aleadingslash, though.
122122
*/
123123
trim_trailing_separator(path);
124+
125+
/*
126+
* Remove any trailing uses of "." or "..", too.
127+
*/
128+
for (;;)
129+
{
130+
intlen=strlen(path);
131+
132+
if (len >=2&&strcmp(path+len-2,"/.")==0)
133+
{
134+
trim_directory(path);
135+
trim_trailing_separator(path);
136+
}
137+
elseif (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
#ifdefWIN32
445467
/*
446468
*Skip over network and drive specifiers for win32.
447-
*Set 'path' to point to the last characterto keep.
469+
*Set 'path' to point to the last characterwe must keep.
448470
*/
449471
if (strlen(path) >=2)
450472
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp