Wrap mkstemp calls with umask set/restore.

glibc versions 2.06 and earlier did not set a umask on files created by
mkstemp created the world-writable.  Wrap mkstemp to set and restore
the umask.  From Coverity (CIDs 291826 291886 291891), ok djm@
This commit is contained in:
Darren Tucker 2023-03-10 13:27:29 +11:00
parent 633d3dc2a1
commit 77adde4305
No known key found for this signature in database
2 changed files with 24 additions and 0 deletions

View File

@ -34,6 +34,28 @@
#include <ctype.h>
#include <unistd.h>
#ifdef mkstemp
#undef mkstemp
#endif
/*
* From glibc man page: 'In glibc versions 2.06 and earlier, the file is
* created with permissions 0666, that is, read and write for all users.'
* Provide a wrapper to make sure the mask is reasonable (POSIX requires
* mode 0600, so mask off any other bits).
*/
int
_ssh_mkstemp(char *template)
{
mode_t mask;
int ret;
mask = umask(0177);
ret = mkstemp(template);
(void)umask(mask);
return ret;
}
#if !defined(HAVE_MKDTEMP)
#define MKTEMP_NAME 0

View File

@ -141,6 +141,8 @@ int mkstemp(char *path);
char *mkdtemp(char *path);
#endif
#define mkstemp(x) _ssh_mkstemp(x)
#ifndef HAVE_DAEMON
int daemon(int nochdir, int noclose);
#endif