diff options
author | Noah Misch <noah@leadboat.com> | 2015-09-20 20:42:27 -0400 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2015-09-20 20:44:23 -0400 |
commit | 5dc49efe9012793110ef5dab9a9a1a7730a70e3f (patch) | |
tree | a2647fc981497164501958c5766577d40508f244 | |
parent | 553ce7e9a8d147cae75f0656a628c29dcbe498d8 (diff) | |
download | postgresql-5dc49efe9012793110ef5dab9a9a1a7730a70e3f.tar.gz postgresql-5dc49efe9012793110ef5dab9a9a1a7730a70e3f.zip |
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.
-rw-r--r-- | src/bin/pg_dump/pg_backup_tar.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c index bd2ba7add95..7995f6e19f2 100644 --- a/src/bin/pg_dump/pg_backup_tar.c +++ b/src/bin/pg_dump/pg_backup_tar.c @@ -372,8 +372,18 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode) } else { + int old_umask; + tm = calloc(1, 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 tm->tmpFH = tmpfile(); #else @@ -408,6 +418,8 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode) if (tm->tmpFH == NULL) die_horribly(AH, modulename, "could not generate temporary file name: %s\n", strerror(errno)); + umask(old_umask); + #ifdef HAVE_LIBZ if (AH->compression != 0) |