summaryrefslogtreecommitdiff
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:05:40 -0400
commite0f5710c5e8b9502ac8bcd821d3418053ed38f7a (patch)
treee9a597ffe1ce6ea8fe20a9a3b66e23475fa284e0 /src/backend/commands/copy.c
parent2020f90bf6753dea790caa7dd9983b6edd5b17c5 (diff)
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 e71b9abdeff..29c2a48520f 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -1570,7 +1570,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,