Blame SOURCES/cups-str3382.patch

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