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/libpq/be-fsstubs.c | |
parent | 58ffe141eb37c3f027acd25c1fc6b36513bf9380 (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/libpq/be-fsstubs.c')
-rw-r--r-- | src/backend/libpq/be-fsstubs.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c index bf45461b2f1..19b34bfc84a 100644 --- a/src/backend/libpq/be-fsstubs.c +++ b/src/backend/libpq/be-fsstubs.c @@ -538,8 +538,17 @@ be_lo_export(PG_FUNCTION_ARGS) */ text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf)); oumask = umask(S_IWGRP | S_IWOTH); - fd = OpenTransientFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + PG_TRY(); + { + fd = OpenTransientFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + } + PG_CATCH(); + { + umask(oumask); + PG_RE_THROW(); + } + PG_END_TRY(); umask(oumask); if (fd < 0) ereport(ERROR, |