Skip to content

Commit 7496aba

Browse files
committed
Restrict file mode creation mask during tmpfile().
Per Coverity. Back-patch to 9.0 (all supported versions). Michael Paquier, reviewed (in earlier versions) by Heikki Linnakangas.
1 parent e32c5f1 commit 7496aba

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/bin/pg_dump/pg_backup_tar.c

+12
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,18 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
380380
}
381381
else
382382
{
383+
int old_umask;
384+
383385
tm = pg_malloc0(sizeof(TAR_MEMBER));
384386

387+
/*
388+
* POSIX does not require, but permits, tmpfile() to restrict file
389+
* permissions. Given an OS crash after we write data, the filesystem
390+
* might retain the data but forget tmpfile()'s unlink(). If so, the
391+
* file mode protects confidentiality of the data written.
392+
*/
393+
old_umask = umask(S_IRWXG | S_IRWXO);
394+
385395
#ifndef WIN32
386396
tm->tmpFH = tmpfile();
387397
#else
@@ -416,6 +426,8 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
416426
if (tm->tmpFH == NULL)
417427
exit_horribly(modulename, "could not generate temporary file name: %s\n", strerror(errno));
418428

429+
umask(old_umask);
430+
419431
#ifdef HAVE_LIBZ
420432

421433
if (AH->compression != 0)

0 commit comments

Comments
 (0)