diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2017-09-22 16:50:59 -0400 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2017-09-22 17:10:36 -0400 |
commit | aa6b7b72d9bcf967cbccd378de4bc5cef33d02f9 (patch) | |
tree | 99233d881a9032f8183c3a530b7c451d6f7e049d /src/backend/commands/copy.c | |
parent | 58ffe141eb37c3f027acd25c1fc6b36513bf9380 (diff) | |
download | postgresql-aa6b7b72d9bcf967cbccd378de4bc5cef33d02f9.tar.gz postgresql-aa6b7b72d9bcf967cbccd378de4bc5cef33d02f9.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.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index c6fa44563c9..7c004ffad8a 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -1826,7 +1826,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) { |