summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut2017-09-22 20:50:59 +0000
committerPeter Eisentraut2017-09-23 14:14:30 +0000
commit2eb84e54a25098618724ee633fbad78d5e417489 (patch)
tree6fec6fb81cc4c5b62622e29804939293bd96b959 /src
parenta07105afacba5895df2e0aa38adb65e242c75b22 (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')
-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 55192741aa6..4a3d027ca3a 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -1423,7 +1423,16 @@ BeginCopyTo(Relation rel,
cstate->filename = pstrdup(filename);
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)
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index 6f7e474f675..695a05d360c 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -474,8 +474,17 @@ lo_export(PG_FUNCTION_ARGS)
*/
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
oumask = umask(S_IWGRP | S_IWOTH);
- fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ PG_TRY();
+ {
+ fd = PathNameOpenFile(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,