8000 Fix saving and restoring umask · yazun/postgres@2eb84e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2eb84e5

Browse files
committed
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.
1 parent a07105a commit 2eb84e5

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/backend/commands/copy.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,16 @@ BeginCopyTo(Relation rel,
14231423

14241424
cstate->filename = pstrdup(filename);
14251425
oumask = umask(S_IWGRP | S_IWOTH);
1426-
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
1426+
PG_TRY();
1427+
{
1428+
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
1429+
}
1430+
PG_CATCH();
1431+
{
1432+
umask(oumask);
1433+
PG_RE_THROW();
1434+
}
1435+
PG_END_TRY();
14271436
umask(oumask);
14281437

14291438
if (cstate->copy_file == NULL)

src/backend/libpq/be-fsstubs.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,17 @@ lo_export(PG_FUNCTION_ARGS)
474474
*/
475475
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
476476
oumask = umask(S_IWGRP | S_IWOTH);
477-
fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
478-
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
477+
PG_TRY();
478+
{
479+
fd = PathNameOpenFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
480+
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
481+
}
482+
PG_CATCH();
483+
{
484+
umask(oumask);
485+
PG_RE_THROW();
486+
}
487+
PG_END_TRY();
479488
umask(oumask);
480489
if (fd < 0)
481490
ereport(ERROR,

0 commit comments

Comments
 (0)
0