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.
This commit is contained in:
Peter Eisentraut 2017-09-22 16:50:59 -04:00
parent a07105afac
commit 2eb84e54a2
2 changed files with 21 additions and 3 deletions

View File

@ -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)

View File

@ -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,