Skip to content

Commit 3d7f11a

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 3571a53 commit 3d7f11a

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
@@ -1822,7 +1822,16 @@ BeginCopyTo(ParseState *pstate,
18221822
errmsg("relative path not allowed for COPY to file")));
18231823

18241824
oumask = umask(S_IWGRP | S_IWOTH);
1825-
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
1825+
PG_TRY();
1826+
{
1827+
cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W);
1828+
}
1829+
PG_CATCH();
1830+
{
1831+
umask(oumask);
1832+
PG_RE_THROW();
1833+
}
1834+
PG_END_TRY();
18261835
umask(oumask);
18271836
if (cstate->copy_file == NULL)
18281837
{

src/backend/libpq/be-fsstubs.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,17 @@ be_lo_export(PG_FUNCTION_ARGS)
538538
*/
539539
text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
540540
oumask = umask(S_IWGRP | S_IWOTH);
541-
fd = OpenTransientFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
542-
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
541+
PG_TRY();
542+
{
543+
fd = OpenTransientFile(fnamebuf, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY,
544+
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
545+
}
546+
PG_CATCH();
547+
{
548+
umask(oumask);
549+
PG_RE_THROW();
550+
}
551+
PG_END_TRY();
543552
umask(oumask);
544553
if (fd < 0)
545554
ereport(ERROR,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy