Blame SOURCES/cups-str3382.patch

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