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