summaryrefslogtreecommitdiff
path: root/src/bin/psql/copy.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-02-23 21:46:03 +0000
committerBruce Momjian <bruce@momjian.us>2002-02-23 21:46:03 +0000
commit5f644ea699ae17dcb50a82122a2172154247f267 (patch)
tree9e9d5206ea89b3c8272a376d527365632f30db8c /src/bin/psql/copy.c
parentec4027f85b260c8d4be4e05d4c3d42fef2d64c63 (diff)
Add fstat / S_ISDIR checks to make sure we're not trying to use a
directory for COPY TO/FROM. Brent Verner
Diffstat (limited to 'src/bin/psql/copy.c')
-rw-r--r--src/bin/psql/copy.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index 0f5cb1e8d83..e374e698eba 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -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))