Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3d7f11a

Browse files
committed
Fix saving and restoring umask
In two cases, we set a different umask for some piece of code andrestore it afterwards. But if the contained code errors out, the umaskis not restored. So add TRY/CATCH blocks to fix that.
1 parent3571a53 commit3d7f11a

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)

[8]ページ先頭

©2009-2025 Movatter.jp