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