Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2ea9595

Browse files
committed
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.
1 parent 8cadeb7 commit 2ea9595

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/backend/commands/copy.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,9 @@ BeginCopyTo(Relation rel,
17071707
errmsg("could not open file \"%s\" for writing: %m",
17081708
cstate->filename)));
17091709

1710-
fstat(fileno(cstate->copy_file), &st);
1710+
if (fstat(fileno(cstate->copy_file), &st))
1711+
elog(ERROR, "could not stat file \"%s\": %m", cstate->filename);
1712+
17111713
if (S_ISDIR(st.st_mode))
17121714
ereport(ERROR,
17131715
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
@@ -2718,7 +2720,9 @@ BeginCopyFrom(Relation rel,
27182720
errmsg("could not open file \"%s\" for reading: %m",
27192721
cstate->filename)));
27202722

2721-
fstat(fileno(cstate->copy_file), &st);
2723+
if (fstat(fileno(cstate->copy_file), &st))
2724+
elog(ERROR, "could not stat file \"%s\": %m", cstate->filename);
2725+
27222726
if (S_ISDIR(st.st_mode))
27232727
ereport(ERROR,
27242728
(errcode(ERRCODE_WRONG_OBJECT_TYPE),

0 commit comments

Comments
 (0)