Skip to content

Commit 8346218

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 ba51774 commit 8346218

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
@@ -379,8 +379,18 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
379379
}
380380
else
381381
{
382+
int old_umask;
383+
382384
tm = pg_malloc0(sizeof(TAR_MEMBER));
383385

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

428+
umask(old_umask);
429+
418430
#ifdef HAVE_LIBZ
419431

420432
if (AH->compression != 0)

0 commit comments

Comments
 (0)