aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/copy.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2017-09-22 16:50:59 -0400
committerPeter Eisentraut <peter_e@gmx.net>2017-09-23 10:03:36 -0400
commita1f30ecc5115b0186ad02ec76f75296906813d26 (patch)
tree064b8c5ca75850801e61326fc44b9e51a943476d /src/backend/commands/copy.c
parente25f4401dad7829463efff1f4655f2c6d6b076ff (diff)
downloadpostgresql-a1f30ecc5115b0186ad02ec76f75296906813d26.tar.gz
postgresql-a1f30ecc5115b0186ad02ec76f75296906813d26.zip
Fix saving and restoring umask
In two cases, we set a different umask for some piece of code and restore it afterwards. But if the contained code errors out, the umask is not restored. So add TRY/CATCH blocks to fix that.
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r--src/backend/commands/copy.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 41a828c2fe4..feab7aa6e2a 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -1802,7 +1802,16 @@ BeginCopyTo(Relation rel,
errmsg("relative path not allowed for COPY to file")));
oumask = umask(S_IWGRP | S_IWOTH);
- cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
+ PG_TRY();
+ {
+ cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
+ }
+ PG_CATCH();
+ {
+ umask(oumask);
+ PG_RE_THROW();
+ }
+ PG_END_TRY();
umask(oumask);
if (cstate->copy_file == NULL)
ereport(ERROR,