Skip to content
Snippets Groups Projects
Commit 8346218c authored by Noah Misch's avatar Noah Misch
Browse files

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.
parent ba51774d
No related branches found
No related tags found
No related merge requests found
...@@ -379,8 +379,18 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode) ...@@ -379,8 +379,18 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
} }
else else
{ {
int old_umask;
tm = pg_malloc0(sizeof(TAR_MEMBER)); tm = pg_malloc0(sizeof(TAR_MEMBER));
/*
* POSIX does not require, but permits, tmpfile() to restrict file
* permissions. Given an OS crash after we write data, the filesystem
* might retain the data but forget tmpfile()'s unlink(). If so, the
* file mode protects confidentiality of the data written.
*/
old_umask = umask(S_IRWXG | S_IRWXO);
#ifndef WIN32 #ifndef WIN32
tm->tmpFH = tmpfile(); tm->tmpFH = tmpfile();
#else #else
...@@ -415,6 +425,8 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode) ...@@ -415,6 +425,8 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
if (tm->tmpFH == NULL) if (tm->tmpFH == NULL)
exit_horribly(modulename, "could not generate temporary file name: %s\n", strerror(errno)); exit_horribly(modulename, "could not generate temporary file name: %s\n", strerror(errno));
umask(old_umask);
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
if (AH->compression != 0) if (AH->compression != 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment