aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>1999-08-23 05:02:50 +0000
committerGuy Harris <guy@alum.mit.edu>1999-08-23 05:02:50 +0000
commit3a2f97bce980de72f52aaf1f08787f25b73ba755 (patch)
treef63f269652505b9360375355016d261e0dfa8f5f /util.c
parent73df88f11eeee326848d6848a67037b065c74b69 (diff)
downloadwireshark-3a2f97bce980de72f52aaf1f08787f25b73ba755.tar.gz
wireshark-3a2f97bce980de72f52aaf1f08787f25b73ba755.tar.bz2
wireshark-3a2f97bce980de72f52aaf1f08787f25b73ba755.zip
The Single UNIX Specification doesn't say that "mkstemp()" creates the
temporary file with mode rw-------, so we won't assume that all UNIXes will do so; instead, we set the umask to 0077 to take away all group and other permissions, attempt to create the file, and then put the umask back (puts into "try_tempfile()", called by "create_tempfile()" to create temporary files, the "umask()" calls that Gilbert put into "capture.c" to deal with the same problem). svn path=/trunk/; revision=553
Diffstat (limited to 'util.c')
-rw-r--r--util.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/util.c b/util.c
index a747ee7ae2..0ecfaa0a35 100644
--- a/util.c
+++ b/util.c
@@ -1,7 +1,7 @@
/* util.c
* Utility routines
*
- * $Id: util.c,v 1.18 1999/08/18 15:29:06 gram Exp $
+ * $Id: util.c,v 1.19 1999/08/23 05:02:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -45,6 +45,14 @@
#include <unistd.h>
#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
#ifdef NEED_SNPRINTF_H
# ifdef HAVE_STDARG_H
# include <stdarg.h>
@@ -201,6 +209,8 @@ try_tempfile(char *namebuf, int namebuflen, const char *dir, const char *pfx)
{
static const char suffix[] = "XXXXXXXXXX";
int namelen = strlen(namebuf) + strlen(pfx) + sizeof suffix;
+ mode_t old_umask;
+ int tmp_fd;
if (namebuflen < namelen) {
errno = ENAMETOOLONG;
@@ -209,7 +219,17 @@ try_tempfile(char *namebuf, int namebuflen, const char *dir, const char *pfx)
strcpy(namebuf, dir);
strcat(namebuf, pfx);
strcat(namebuf, suffix);
- return mkstemp(namebuf);
+
+ /* The Single UNIX Specification doesn't say that "mkstemp()"
+ creates the temporary file with mode rw-------, so we
+ won't assume that all UNIXes will do so; instead, we set
+ the umask to 0077 to take away all group and other
+ permissions, attempt to create the file, and then put
+ the umask back. */
+ old_umask = umask(0077);
+ tmp_fd = mkstemp(namebuf);
+ umask(old_umask);
+ return tmp_fd;
}
static char *tmpdir = NULL;