summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorAndres Freund2015-01-04 15:47:23 +0000
committerAndres Freund2015-01-04 15:47:23 +0000
commit2ea95959afa225118374ab1691a5ccf84ae05ce8 (patch)
treee4ebce46fdfd6fd6669ca237554b3491ad9cbef4 /src/backend
parent8cadeb792cd08478a73cb0941bb67f03e8465090 (diff)
Add error handling for failing fstat() calls in copy.c.
These calls are pretty much guaranteed not to fail unless something has gone horribly wrong, and even in that case we'd just error out a short time later. But since several code checkers complain about the missing check it seems worthwile to fix it nonetheless. Pointed out by Coverity.
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/commands/copy.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 08abe141f4..8b1c727b33 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -1707,7 +1707,9 @@ BeginCopyTo(Relation rel,
errmsg("could not open file \"%s\" for writing: %m",
cstate->filename)));
- fstat(fileno(cstate->copy_file), &st);
+ if (fstat(fileno(cstate->copy_file), &st))
+ elog(ERROR, "could not stat file \"%s\": %m", cstate->filename);
+
if (S_ISDIR(st.st_mode))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
@@ -2718,7 +2720,9 @@ BeginCopyFrom(Relation rel,
errmsg("could not open file \"%s\" for reading: %m",
cstate->filename)));
- fstat(fileno(cstate->copy_file), &st);
+ if (fstat(fileno(cstate->copy_file), &st))
+ elog(ERROR, "could not stat file \"%s\": %m", cstate->filename);
+
if (S_ISDIR(st.st_mode))
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),