Index: src/backend/commands/copy.c =================================================================== RCS file: /var/cvsup/pgsql/src/backend/commands/copy.c,v retrieving revision 1.144 diff -c -r1.144 copy.c *** src/backend/commands/copy.c 4 Dec 2001 21:19:57 -0000 1.144 --- src/backend/commands/copy.c 17 Jan 2002 12:24:17 -0000 *************** *** 326,337 **** } else { fp = AllocateFile(filename, PG_BINARY_R); ! 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); } CopyFrom(rel, binary, oids, fp, delim, null_print); } --- 326,345 ---- } else { + struct stat st; fp = AllocateFile(filename, PG_BINARY_R); ! ! 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,365 **** --- 368,374 ---- else { mode_t oumask; /* Pre-existing umask value */ + struct stat st; /* * Prevent write to relative path ... too easy to shoot *************** *** 378,383 **** --- 387,397 ---- "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); } Index: src/bin/psql/copy.c =================================================================== RCS file: /var/cvsup/pgsql/src/bin/psql/copy.c,v retrieving revision 1.19 diff -c -r1.19 copy.c *** src/bin/psql/copy.c 2 Jun 2001 18:25:18 -0000 1.19 --- src/bin/psql/copy.c 17 Jan 2002 12:25:07 -0000 *************** *** 11,16 **** --- 11,17 ---- #include #include #include + #include #ifndef WIN32 #include /* for isatty */ #else *************** *** 233,238 **** --- 234,240 ---- struct copy_options *options; PGresult *result; bool success; + struct stat st; /* parse options */ options = parse_slash_copy(args); *************** *** 292,298 **** free_copy_options(options); return false; } ! result = PSQLexec(query); switch (PQresultStatus(result)) --- 294,309 ---- 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))