[openssh-commits] [openssh] 01/02: Wrap mkstemp calls with umask set/restore.

git+noreply at mindrot.org git+noreply at mindrot.org
Fri Mar 10 13:53:13 AEDT 2023


This is an automated email from the git hooks/post-receive script.

dtucker pushed a commit to branch master
in repository openssh.

commit 77adde4305542ebe3005dd456122624fe2347b01
Author: Darren Tucker <dtucker at dtucker.net>
Date:   Fri Mar 10 13:27:29 2023 +1100

    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@
---
 openbsd-compat/mktemp.c         | 22 ++++++++++++++++++++++
 openbsd-compat/openbsd-compat.h |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/openbsd-compat/mktemp.c b/openbsd-compat/mktemp.c
index ac922c1e..4b13b983 100644
--- a/openbsd-compat/mktemp.c
+++ b/openbsd-compat/mktemp.c
@@ -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
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 895ecf9e..cc4cf205 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -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

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list