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:05 -0400
commit3d7f11a0fabb038ce5c630b87dfadd8b625347fe (patch)
treed96289a6135e8409e259238fe79d885de27021f0 /src/backend/commands/copy.c
parent3571a53345bb4d3d055d8a720e9817038927877e (diff)
downloadpostgresql-3d7f11a0fabb038ce5c630b87dfadd8b625347fe.tar.gz
postgresql-3d7f11a0fabb038ce5c630b87dfadd8b625347fe.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 ad1fcd8d77b..ef81e3be711 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -1822,7 +1822,16 @@ BeginCopyTo(ParseState *pstate,
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)
{