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
5f644ea6
Commit
5f644ea6
authored
Feb 23, 2002
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fstat / S_ISDIR checks to make sure we're not trying to use a
directory for COPY TO/FROM. Brent Verner
parent
ec4027f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
4 deletions
+29
-4
src/backend/commands/copy.c
src/backend/commands/copy.c
+16
-2
src/bin/psql/copy.c
src/bin/psql/copy.c
+13
-2
No files found.
src/backend/commands/copy.c
View file @
5f644ea6
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.14
5 2002/02/12 21:25:41 tgl
Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.14
6 2002/02/23 21:46:02 momjian
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -326,12 +326,20 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
}
else
{
struct
stat
st
;
fp
=
AllocateFile
(
filename
,
PG_BINARY_R
);
if
(
fp
==
NULL
)
if
(
fp
==
NULL
)
elog
(
ERROR
,
"COPY command, running in backend with "
"effective uid %d, could not open file '%s' for "
"reading. Errno = %s (%d)."
,
(
int
)
geteuid
(),
filename
,
strerror
(
errno
),
errno
);
fstat
(
fileno
(
fp
),
&
st
);
if
(
S_ISDIR
(
st
.
st_mode
)
){
fclose
(
fp
);
elog
(
ERROR
,
"COPY: %s is a directory."
,
filename
);
}
}
CopyFrom
(
rel
,
binary
,
oids
,
fp
,
delim
,
null_print
);
}
...
...
@@ -360,6 +368,7 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
else
{
mode_t
oumask
;
/* Pre-existing umask value */
struct
stat
st
;
/*
* Prevent write to relative path ... too easy to shoot
...
...
@@ -378,6 +387,11 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
"effective uid %d, could not open file '%s' for "
"writing. Errno = %s (%d)."
,
(
int
)
geteuid
(),
filename
,
strerror
(
errno
),
errno
);
fstat
(
fileno
(
fp
),
&
st
);
if
(
S_ISDIR
(
st
.
st_mode
)
){
fclose
(
fp
);
elog
(
ERROR
,
"COPY: %s is a directory."
,
filename
);
}
}
CopyTo
(
rel
,
binary
,
oids
,
fp
,
delim
,
null_print
);
}
...
...
src/bin/psql/copy.c
View file @
5f644ea6
...
...
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.
19 2001/06/02 18:25:18 petere
Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.
20 2002/02/23 21:46:03 momjian
Exp $
*/
#include "postgres_fe.h"
#include "copy.h"
...
...
@@ -11,6 +11,7 @@
#include <errno.h>
#include <assert.h>
#include <signal.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
/* for isatty */
#else
...
...
@@ -233,6 +234,7 @@ do_copy(const char *args)
struct
copy_options
*
options
;
PGresult
*
result
;
bool
success
;
struct
stat
st
;
/* parse options */
options
=
parse_slash_copy
(
args
);
...
...
@@ -292,7 +294,16 @@ do_copy(const char *args)
free_copy_options
(
options
);
return
false
;
}
/* make sure the specified file is not a directory */
fstat
(
fileno
(
copystream
),
&
st
);
if
(
S_ISDIR
(
st
.
st_mode
)
){
fclose
(
copystream
);
psql_error
(
"%s: cannot COPY TO/FROM a directory
\n
"
,
options
->
file
);
free_copy_options
(
options
);
return
false
;
}
result
=
PSQLexec
(
query
);
switch
(
PQresultStatus
(
result
))
...
...
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