Skip to content

Commit 24aed21

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 eed5bbc commit 24aed21

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,18 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
375375
}
376376
else
377377
{
378+
int old_umask;
379+
378380
tm = calloc(1, sizeof(TAR_MEMBER));
379381

382+
/*
383+
* POSIX does not require, but permits, tmpfile() to restrict file
384+
* permissions. Given an OS crash after we write data, the filesystem
385+
* might retain the data but forget tmpfile()'s unlink(). If so, the
386+
* file mode protects confidentiality of the data written.
387+
*/
388+
old_umask = umask(S_IRWXG | S_IRWXO);
389+
380390
#ifndef WIN32
381391
tm->tmpFH = tmpfile();
382392
#else
@@ -411,6 +421,8 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
411421
if (tm->tmpFH == NULL)
412422
die_horribly(AH, modulename, "could not generate temporary file name: %s\n", strerror(errno));
413423

424+
umask(old_umask);
425+
414426
#ifdef HAVE_LIBZ
415427

416428
if (AH->compression != 0)

0 commit comments

Comments
 (0)