Content-Length: 283478 | pFad | http://github.com/postgrespro/postgres/commit/2ea95959afa225118374ab1691a5ccf84ae05ce8

02 Add error handling for failing fstat() calls in copy.c. · postgrespro/postgres@2ea9595 · GitHub
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

Lines changed: 6 additions & 2 deletions
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)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/2ea95959afa225118374ab1691a5ccf84ae05ce8

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy