Blame SOURCES/cups-str3382.patch

1d75c0
diff -up cups-2.0rc1/cups/tempfile.c.str3382 cups-2.0rc1/cups/tempfile.c
1d75c0
--- cups-2.0rc1/cups/tempfile.c.str3382	2014-07-31 02:58:00.000000000 +0200
1d75c0
+++ cups-2.0rc1/cups/tempfile.c	2014-09-12 14:06:42.560887827 +0200
1d75c0
@@ -27,6 +27,7 @@
1d75c0
 #  include <io.h>
1d75c0
 #else
1d75c0
 #  include <unistd.h>
1d75c0
+#  include <sys/types.h>
1d75c0
 #endif /* WIN32 || __EMX__ */
1d75c0
 
1d75c0
 
1d75c0
@@ -48,7 +49,7 @@ cupsTempFd(char *filename,		/* I - Point
1d75c0
   char		tmppath[1024];		/* Windows temporary directory */
1d75c0
   DWORD		curtime;		/* Current time */
1d75c0
 #else
1d75c0
-  struct timeval curtime;		/* Current time */
1d75c0
+  mode_t	old_umask;		/* Old umask before using mkstemp() */
1d75c0
 #endif /* WIN32 */
1d75c0
 
1d75c0
 
1d75c0
@@ -98,32 +99,24 @@ cupsTempFd(char *filename,		/* I - Point
1d75c0
     */
1d75c0
 
1d75c0
     snprintf(filename, (size_t)len - 1, "%s/%05lx%08lx", tmpdir, GetCurrentProcessId(), curtime);
1d75c0
-#else
1d75c0
-   /*
1d75c0
-    * Get the current time of day...
1d75c0
-    */
1d75c0
-
1d75c0
-    gettimeofday(&curtime, NULL);
1d75c0
-
1d75c0
-   /*
1d75c0
-    * Format a string using the hex time values...
1d75c0
-    */
1d75c0
-
1d75c0
-    snprintf(filename, (size_t)len - 1, "%s/%05x%08x", tmpdir, (unsigned)getpid(), (unsigned)(curtime.tv_sec + curtime.tv_usec + tries));
1d75c0
-#endif /* WIN32 */
1d75c0
 
1d75c0
    /*
1d75c0
     * Open the file in "exclusive" mode, making sure that we don't
1d75c0
     * stomp on an existing file or someone's symlink crack...
1d75c0
     */
1d75c0
 
1d75c0
-#ifdef WIN32
1d75c0
     fd = open(filename, _O_CREAT | _O_RDWR | _O_TRUNC | _O_BINARY,
1d75c0
               _S_IREAD | _S_IWRITE);
1d75c0
-#elif defined(O_NOFOLLOW)
1d75c0
-    fd = open(filename, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);
1d75c0
 #else
1d75c0
-    fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
1d75c0
+   /*
1d75c0
+    * Use the standard mkstemp() call to make a temporary filename
1d75c0
+    * securely.  -- andrew.wood@jdplc.com
1d75c0
+    */
1d75c0
+    snprintf(filename, len - 1, "%s/cupsXXXXXX", tmpdir);
1d75c0
+
1d75c0
+    old_umask = umask(0077);
1d75c0
+    fd = mkstemp(filename);
1d75c0
+    umask(old_umask);
1d75c0
 #endif /* WIN32 */
1d75c0
 
1d75c0
     if (fd < 0 && errno != EEXIST)