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-23 10:04:55 -0400 |
commit | acae13faabc505146817f4834a8c9e9b43788312 (patch) | |
tree | 9f41e6f77dadd4ce4bd4ac782569f6d032fd4a6c /src/backend/commands/copy.c | |
parent | 89f02e17a6ac81bbc78ea92f2ead06d8816ee297 (diff) | |
download | postgresql-acae13faabc505146817f4834a8c9e9b43788312.tar.gz postgresql-acae13faabc505146817f4834a8c9e9b43788312.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 f93d4ed7cfc..808ea09eeb2 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -1764,7 +1764,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, |