mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Add fstat / S_ISDIR checks to make sure we're not trying to use a
directory for COPY TO/FROM. Brent Verner
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.145 2002/02/12 21:25:41 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.146 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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user