Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
35379e90
Commit
35379e90
authored
Aug 12, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify canonicalize_path() so if we would return a trailing "..", throw
an error instead.
parent
a43ea120
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
21 deletions
+59
-21
src/backend/postmaster/postmaster.c
src/backend/postmaster/postmaster.c
+6
-3
src/port/Makefile
src/port/Makefile
+3
-2
src/port/path.c
src/port/path.c
+50
-16
No files found.
src/backend/postmaster/postmaster.c
View file @
35379e90
...
...
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.46
4 2005/08/12 18:23:53 tgl
Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.46
5 2005/08/12 19:42:44 momjian
Exp $
*
* NOTES
*
...
...
@@ -377,8 +377,11 @@ PostmasterMain(int argc, char *argv[])
char
*
userDoption
=
NULL
;
int
i
;
/* This will call exit() if strdup() fails. */
progname
=
get_progname
(
argv
[
0
]);
if
((
progname
=
get_progname
(
argv
[
0
]))
==
NULL
)
{
printf
(
_
(
"unable to allocate memory for program name
\"
%s
\"
.
\n
"
),
progname
);
ExitPostmaster
(
0
);
}
MyProcPid
=
PostmasterPid
=
getpid
();
...
...
src/port/Makefile
View file @
35379e90
...
...
@@ -15,7 +15,7 @@
# for use only by the backend binaries
#
# IDENTIFICATION
# $PostgreSQL: pgsql/src/port/Makefile,v 1.2
5 2005/03/20 03:53:39
momjian Exp $
# $PostgreSQL: pgsql/src/port/Makefile,v 1.2
6 2005/08/12 19:42:45
momjian Exp $
#
#-------------------------------------------------------------------------
...
...
@@ -31,6 +31,7 @@ LIBOBJS_SRV := $(LIBOBJS)
LIBOBJS_SRV
:=
$(
patsubst
dirmod.o,dirmod_srv.o,
$(LIBOBJS_SRV)
)
LIBOBJS_SRV
:=
$(
patsubst
exec.o,exec_srv.o,
$(LIBOBJS_SRV)
)
LIBOBJS_SRV
:=
$(
patsubst
getaddrinfo.o,getaddrinfo_srv.o,
$(LIBOBJS_SRV)
)
LIBOBJS_SRV
:=
$(
patsubst
path.o,path_srv.o,
$(LIBOBJS_SRV)
)
LIBOBJS_SRV
:=
$(
patsubst
thread.o,thread_srv.o,
$(LIBOBJS_SRV)
)
all
:
libpgport.a libpgport_srv.a
...
...
@@ -66,7 +67,7 @@ exec_srv.o: exec.c
getaddrinfo_srv.o
:
getaddrinfo.c
$(CC)
$(CFLAGS)
$(
subst
-DFRONTEND
,,
$(CPPFLAGS)
)
-c
$<
-o
$@
snprintf_srv.o
:
snprintf
.c
path_srv.o
:
path
.c
$(CC)
$(CFLAGS)
$(
subst
-DFRONTEND
,,
$(CPPFLAGS)
)
-c
$<
-o
$@
# No thread flags for server version
...
...
src/port/path.c
View file @
35379e90
...
...
@@ -8,12 +8,16 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/port/path.c,v 1.5
4 2005/08/12 03:07
:45 momjian Exp $
* $PostgreSQL: pgsql/src/port/path.c,v 1.5
5 2005/08/12 19:42
:45 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "c.h"
#ifndef FRONTEND
#include "postgres.h"
#else
#include "postgres_fe.h"
#endif
#include <ctype.h>
#include <sys/stat.h>
...
...
@@ -226,6 +230,7 @@ canonicalize_path(char *path)
{
char
*
p
,
*
to_p
;
bool
was_sep
=
false
;
int
pending_strips
=
0
;
#ifdef WIN32
/*
...
...
@@ -284,19 +289,38 @@ canonicalize_path(char *path)
if
(
len
>
2
&&
strcmp
(
path
+
len
-
2
,
"/."
)
==
0
)
trim_directory
(
path
);
/*
* Process only a single trailing "..", and only if ".." does
* not preceed it.
* So, we only deal with "/usr/local/..", not with "/usr/local/../..".
* We don't handle the even more complex cases, like
* "usr/local/../../..".
*/
else
if
(
len
>
3
&&
strcmp
(
path
+
len
-
3
,
"/.."
)
==
0
&&
(
len
!=
5
||
strcmp
(
path
,
"../.."
)
!=
0
)
&&
(
len
<
6
||
strcmp
(
path
+
len
-
6
,
"/../.."
)
!=
0
))
else
if
(
len
>
3
&&
strcmp
(
path
+
len
-
3
,
"/.."
)
==
0
)
{
trim_directory
(
path
);
trim_directory
(
path
);
/* remove directory above */
pending_strips
++
;
}
else
if
(
pending_strips
>
0
)
{
/* If path is not "", we can keep trimming. Even if path is
* "/", we can keep trimming because trim_directory never removes
* the leading separator, and the parent directory of "/" is "/".
*/
if
(
*
path
!=
'\0'
)
{
trim_directory
(
path
);
pending_strips
--
;
}
else
{
/*
* If we still have pending_strips, it means the supplied path
* was exhausted and we still have more directories to move up.
* This means that the resulting path is only parents, like
* ".." or "../..". If so, callers can not handle trailing "..",
* so we exit.
*/
#ifndef FRONTEND
elog
(
ERROR
,
"relative paths (
\"
..
\"
) not supported"
);
#else
fprintf
(
stderr
,
_
(
"relative paths (
\"
..
\"
) not supported
\n
"
));
exit
(
1
);
#endif
}
}
else
break
;
...
...
@@ -306,7 +330,9 @@ canonicalize_path(char *path)
/*
* Extracts the actual name of the program as called -
* stripped of .exe suffix if any
* stripped of .exe suffix if any.
* The server calling this must check for NULL return
* and report the error.
*/
const
char
*
get_progname
(
const
char
*
argv0
)
...
...
@@ -329,8 +355,16 @@ get_progname(const char *argv0)
progname
=
strdup
(
nodir_name
);
if
(
progname
==
NULL
)
{
#ifndef FRONTEND
/*
* No elog() support in postmaster at this stage,
* so return NULL and print error at the call.
*/
return
NULL
;
#else
fprintf
(
stderr
,
"%s: out of memory
\n
"
,
nodir_name
);
exit
(
1
);
/* This could exit the postmaster */
exit
(
1
);
#endif
}
progname
[
strlen
(
progname
)
-
(
sizeof
(
EXE
)
-
1
)]
=
'\0'
;
nodir_name
=
progname
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment