Blame SOURCES/cups-str3382.patch

87cf9a
diff -up cups-1.5b1/cups/tempfile.c.str3382 cups-1.5b1/cups/tempfile.c
87cf9a
--- cups-1.5b1/cups/tempfile.c.str3382	2010-03-24 01:45:34.000000000 +0100
87cf9a
+++ cups-1.5b1/cups/tempfile.c	2011-05-24 16:04:47.000000000 +0200
87cf9a
@@ -33,6 +33,7 @@
87cf9a
 #  include <io.h>
87cf9a
 #else
87cf9a
 #  include <unistd.h>
87cf9a
+#  include <sys/types.h>
87cf9a
 #endif /* WIN32 || __EMX__ */
87cf9a
 
87cf9a
 
87cf9a
@@ -54,7 +55,7 @@ cupsTempFd(char *filename,		/* I - Point
87cf9a
   char		tmppath[1024];		/* Windows temporary directory */
87cf9a
   DWORD		curtime;		/* Current time */
87cf9a
 #else
87cf9a
-  struct timeval curtime;		/* Current time */
87cf9a
+  mode_t	old_umask;		/* Old umask before using mkstemp() */
87cf9a
 #endif /* WIN32 */
87cf9a
 
87cf9a
 
87cf9a
@@ -105,33 +106,25 @@ cupsTempFd(char *filename,		/* I - Point
87cf9a
 
87cf9a
     snprintf(filename, len - 1, "%s/%05lx%08lx", tmpdir,
87cf9a
              GetCurrentProcessId(), curtime);
87cf9a
-#else
87cf9a
-   /*
87cf9a
-    * Get the current time of day...
87cf9a
-    */
87cf9a
-
87cf9a
-    gettimeofday(&curtime, NULL);
87cf9a
-
87cf9a
-   /*
87cf9a
-    * Format a string using the hex time values...
87cf9a
-    */
87cf9a
-
87cf9a
-    snprintf(filename, len - 1, "%s/%05x%08x", tmpdir, (unsigned)getpid(),
87cf9a
-             (unsigned)(curtime.tv_sec + curtime.tv_usec + tries));
87cf9a
-#endif /* WIN32 */
87cf9a
 
87cf9a
    /*
87cf9a
     * Open the file in "exclusive" mode, making sure that we don't
87cf9a
     * stomp on an existing file or someone's symlink crack...
87cf9a
     */
87cf9a
 
87cf9a
-#ifdef WIN32
87cf9a
     fd = open(filename, _O_CREAT | _O_RDWR | _O_TRUNC | _O_BINARY,
87cf9a
               _S_IREAD | _S_IWRITE);
87cf9a
-#elif defined(O_NOFOLLOW)
87cf9a
-    fd = open(filename, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);
87cf9a
 #else
87cf9a
-    fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
87cf9a
+
87cf9a
+   /*
87cf9a
+    * Use the standard mkstemp() call to make a temporary filename
87cf9a
+    * securely.  -- andrew.wood@jdplc.com
87cf9a
+    */
87cf9a
+    snprintf(filename, len - 1, "%s/cupsXXXXXX", tmpdir);
87cf9a
+
87cf9a
+    old_umask = umask(0077);
87cf9a
+    fd = mkstemp(filename);
87cf9a
+    umask(old_umask);
87cf9a
 #endif /* WIN32 */
87cf9a
 
87cf9a
     if (fd < 0 && errno != EEXIST)