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

Lines changed: 12 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy