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

Commite0f5710

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 parent2020f90 commite0f5710

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
@@ -1570,7 +1570,16 @@ BeginCopyTo(Relation rel,
15701570
errmsg("relative path not allowed for COPY to file")));
15711571

15721572
oumask=umask(S_IWGRP |S_IWOTH);
1573-
cstate->copy_file=AllocateFile(cstate->filename,PG_BINARY_W);
1573+
PG_TRY();
1574+
{
1575+
cstate->copy_file=AllocateFile(cstate->filename,PG_BINARY_W);
1576+
}
1577+
PG_CATCH();
1578+
{
1579+
umask(oumask);
1580+
PG_RE_THROW();
1581+
}
1582+
PG_END_TRY();
15741583
umask(oumask);
15751584
if (cstate->copy_file==NULL)
15761585
ereport(ERROR,

‎src/backend/libpq/be-fsstubs.c

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp