aboutsummaryrefslogtreecommitdiff
path: root/src
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:28 -0400
commit9bf04994697dd094032d08682a25cbba7aba523f (patch)
treef1b0808a5620cc1ad7f20f279705ded076f21732 /src
parentdbd6099fbc7783aa167eebc15a0688a613e16635 (diff)
downloadpostgresql-9bf04994697dd094032d08682a25cbba7aba523f.tar.gz
postgresql-9bf04994697dd094032d08682a25cbba7aba523f.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')
-rw-r--r--src/backend/commands/copy.c11
-rw-r--r--src/backend/libpq/be-fsstubs.c13
2 files changed, 21 insertions, 3 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 3eba9efcc63..71bec156cdb 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -1619,7 +1619,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,
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index bcc90b9be2a..10cb1e14926 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -540,8 +540,17 @@ 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,