mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
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:
parent
58ffe141eb
commit
aa6b7b72d9
@ -1826,7 +1826,16 @@ BeginCopyTo(ParseState *pstate,
|
|||||||
errmsg("relative path not allowed for COPY to file")));
|
errmsg("relative path not allowed for COPY to file")));
|
||||||
|
|
||||||
oumask = umask(S_IWGRP | S_IWOTH);
|
oumask = umask(S_IWGRP | S_IWOTH);
|
||||||
|
PG_TRY();
|
||||||
|
{
|
||||||
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
|
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
|
||||||
|
}
|
||||||
|
PG_CATCH();
|
||||||
|
{
|
||||||
|
umask(oumask);
|
||||||
|
PG_RE_THROW();
|
||||||
|
}
|
||||||
|
PG_END_TRY();
|
||||||
umask(oumask);
|
umask(oumask);
|
||||||
if (cstate->copy_file == NULL)
|
if (cstate->copy_file == NULL)
|
||||||
{
|
{
|
||||||
|
@ -538,8 +538,17 @@ be_lo_export(PG_FUNCTION_ARGS)
|
|||||||
*/
|
*/
|
||||||
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
|
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
|
||||||
oumask = umask(S_IWGRP | S_IWOTH);
|
oumask = umask(S_IWGRP | S_IWOTH);
|
||||||
|
PG_TRY();
|
||||||
|
{
|
||||||
fd = OpenTransientFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
|
fd = OpenTransientFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
|
||||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||||
|
}
|
||||||
|
PG_CATCH();
|
||||||
|
{
|
||||||
|
umask(oumask);
|
||||||
|
PG_RE_THROW();
|
||||||
|
}
|
||||||
|
PG_END_TRY();
|
||||||
umask(oumask);
|
umask(oumask);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user