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