aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ConfigureChecks.cmake2
-rw-r--r--cmakeconfig.h.in4
-rw-r--r--config.h.win322
-rw-r--r--configure.ac2
-rw-r--r--dumpcap.c15
-rw-r--r--extcap.c2
-rw-r--r--file.c2
-rw-r--r--ui/export_pdu_ui_utils.c2
-rw-r--r--ui/gtk/follow_stream.c2
-rw-r--r--ui/gtk/iax2_analysis.c4
-rw-r--r--ui/gtk/print_dlg.c2
-rw-r--r--ui/gtk/rtp_analysis.c4
-rw-r--r--wiretap/file_access.c2
-rw-r--r--wiretap/nettrace_3gpp_32_423.c2
-rw-r--r--wsutil/tempfile.c35
-rw-r--r--wsutil/tempfile.h6
16 files changed, 47 insertions, 41 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index c4c2b47d54..73c24df239 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -119,7 +119,7 @@ check_function_exists("inet_ntop" HAVE_INET_NTOP)
check_function_exists("inet_pton" HAVE_INET_PTON)
check_function_exists("issetugid" HAVE_ISSETUGID)
check_function_exists("mkdtemp" HAVE_MKDTEMP)
-check_function_exists("mkstemp" HAVE_MKSTEMP)
+check_function_exists("mkstemps" HAVE_MKSTEMPS)
check_function_exists("popcount" HAVE_POPCOUNT)
check_function_exists("setresgid" HAVE_SETRESGID)
check_function_exists("setresuid" HAVE_SETRESUID)
diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in
index a965c1c54d..f1addfac69 100644
--- a/cmakeconfig.h.in
+++ b/cmakeconfig.h.in
@@ -178,8 +178,8 @@
/* Define to 1 if you have the `mkdtemp' function. */
#cmakedefine HAVE_MKDTEMP 1
-/* Define to 1 if you have the `mkstemp' function. */
-#cmakedefine HAVE_MKSTEMP 1
+/* Define to 1 if you have the `mkstemps' function. */
+#cmakedefine HAVE_MKSTEMPS 1
/* Define to 1 if you have the `mmap' function. */
#cmakedefine HAVE_MMAP 1
diff --git a/config.h.win32 b/config.h.win32
index d6a11e8fdf..f511ce9fca 100644
--- a/config.h.win32
+++ b/config.h.win32
@@ -41,7 +41,7 @@
#define HAVE_PLUGINS 1
#define HAVE_EXTCAP 1
-/* #undef HAVE_MKSTEMP */
+/* #undef HAVE_MKSTEMPS */
/* #undef HAVE_MKDTEMP */
@HAVE_LIBPCAP@
diff --git a/configure.ac b/configure.ac
index 7ce954fc3f..7d9fe740cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2381,7 +2381,7 @@ AC_REPLACE_FUNCS(inet_ntop)
AC_REPLACE_FUNCS(strptime)
AC_REPLACE_FUNCS(popcount)
-AC_CHECK_FUNCS(mkstemp mkdtemp)
+AC_CHECK_FUNCS(mkstemps mkdtemp)
AC_CHECK_FUNCS(getprotobynumber)
AC_CHECK_FUNCS(issetugid)
AC_CHECK_FUNCS(sysconf)
diff --git a/dumpcap.c b/dumpcap.c
index 21230b7ec7..c38cf63da8 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -2733,7 +2733,7 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
{
char *tmpname;
gchar *capfile_name;
- gchar *prefix;
+ gchar *prefix, *suffix;
gboolean is_tempfile;
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "capture_loop_open_output: %s",
@@ -2787,6 +2787,7 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
/* Choose a random name for the temporary capture buffer */
if (global_capture_opts.ifaces->len > 1) {
prefix = g_strdup_printf("wireshark_%d_interfaces", global_capture_opts.ifaces->len);
+ suffix = NULL;
} else {
gchar *basename;
basename = g_path_get_basename(g_array_index(global_capture_opts.ifaces, interface_options, 0).console_display_name);
@@ -2802,17 +2803,17 @@ capture_loop_open_output(capture_options *capture_opts, int *save_file_fd,
g_string_free(iface, TRUE);
}
#endif
- /* generate the temp file name prefix...
- * It would be nice if we could specify a pcapng/pcap filename suffix,
- * create_tempfile() however currently uses mkstemp() which doesn't allow this - one day perhaps*/
+ /* generate the temp file name prefix and suffix */
if (capture_opts->use_pcapng) {
- prefix = g_strconcat("wireshark_pcapng_", basename, NULL);
+ prefix = g_strconcat("wireshark_", basename, NULL);
+ suffix = ".pcapng";
}else{
- prefix = g_strconcat("wireshark_pcap_", basename, NULL);
+ prefix = g_strconcat("wireshark_", basename, NULL);
+ suffix = ".pcap";
}
g_free(basename);
}
- *save_file_fd = create_tempfile(&tmpname, prefix);
+ *save_file_fd = create_tempfile(&tmpname, prefix, suffix);
g_free(prefix);
capfile_name = g_strdup(tmpname);
is_tempfile = TRUE;
diff --git a/extcap.c b/extcap.c
index 88d32b4719..29f931ac12 100644
--- a/extcap.c
+++ b/extcap.c
@@ -974,7 +974,7 @@ gboolean extcap_create_pipe(char ** fifo)
gchar *temp_name = NULL;
int fd = 0;
- if ((fd = create_tempfile(&temp_name, EXTCAP_PIPE_PREFIX)) < 0 )
+ if ((fd = create_tempfile(&temp_name, EXTCAP_PIPE_PREFIX, NULL)) < 0 )
return FALSE;
ws_close(fd);
diff --git a/file.c b/file.c
index 75a11d4540..b799e21dab 100644
--- a/file.c
+++ b/file.c
@@ -1345,7 +1345,7 @@ cf_merge_files(char **out_filenamep, int in_file_count,
if (out_fd == -1)
err = errno;
} else {
- out_fd = create_tempfile(&tmpname, "wireshark");
+ out_fd = create_tempfile(&tmpname, "wireshark", NULL);
if (out_fd == -1)
err = errno;
out_filename = g_strdup(tmpname);
diff --git a/ui/export_pdu_ui_utils.c b/ui/export_pdu_ui_utils.c
index f923f074a7..133e511df8 100644
--- a/ui/export_pdu_ui_utils.c
+++ b/ui/export_pdu_ui_utils.c
@@ -50,7 +50,7 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
int err;
/* Choose a random name for the temporary import buffer */
- import_file_fd = create_tempfile(&tmpname, "Wireshark_PDU_");
+ import_file_fd = create_tempfile(&tmpname, "Wireshark_PDU_", NULL);
capfile_name = g_strdup(tmpname);
err = exp_pdu_open(exp_pdu_tap_data, import_file_fd,
diff --git a/ui/gtk/follow_stream.c b/ui/gtk/follow_stream.c
index 37482e2e02..d68f15ebb6 100644
--- a/ui/gtk/follow_stream.c
+++ b/ui/gtk/follow_stream.c
@@ -601,7 +601,7 @@ follow_print_stream(GtkWidget * w _U_, gpointer data)
/* Don't use tmpnam() or such, as this will fail under some ACL */
/* circumstances: http://bugs.wireshark.org/bugzilla/show_bug.cgi?id=358 */
/* Also: tmpnam is "insecure" and should not be used. */
- tmp_fd = create_tempfile(&tmp_namebuf, "wshprint");
+ tmp_fd = create_tempfile(&tmp_namebuf, "wshprint", NULL);
if(tmp_fd == -1) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Couldn't create temporary file for printing:\n%s", tmp_namebuf);
diff --git a/ui/gtk/iax2_analysis.c b/ui/gtk/iax2_analysis.c
index d0eceb4a43..604f721ba3 100644
--- a/ui/gtk/iax2_analysis.c
+++ b/ui/gtk/iax2_analysis.c
@@ -3443,7 +3443,7 @@ iax2_analysis(
/* file names for storing sound data */
- fd = create_tempfile(&tempname, "wireshark_iax2_f");
+ fd = create_tempfile(&tempname, "wireshark_iax2_f", NULL);
if (fd < 0) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Can't create temporary file for IAX2 analysis:\n%s.",
@@ -3453,7 +3453,7 @@ iax2_analysis(
}
user_data->f_tempname = g_strdup(tempname);
ws_close(fd);
- fd = create_tempfile(&tempname, "wireshark_iax2_r");
+ fd = create_tempfile(&tempname, "wireshark_iax2_r", NULL);
if (fd < 0) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Can't create temporary file for IAX2 analysis:\n%s.",
diff --git a/ui/gtk/print_dlg.c b/ui/gtk/print_dlg.c
index 262e953695..ee4cddd111 100644
--- a/ui/gtk/print_dlg.c
+++ b/ui/gtk/print_dlg.c
@@ -992,7 +992,7 @@ print_ok_cb(GtkWidget *ok_bt, gpointer parent_w)
/* Don't use tmpnam() or such, as this will fail under some ACL */
/* circumstances: http://bugs.wireshark.org/bugzilla/show_bug.cgi?id=358 */
/* Also: tmpnam is "insecure" and should not be used. */
- tmp_fd = create_tempfile(&tmp_namebuf, "wshprint");
+ tmp_fd = create_tempfile(&tmp_namebuf, "wshprint", NULL);
if(tmp_fd == -1) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Couldn't create a temporary file for printing:\n%s", tmp_namebuf);
diff --git a/ui/gtk/rtp_analysis.c b/ui/gtk/rtp_analysis.c
index 9c1f6f685f..daaa6d38e8 100644
--- a/ui/gtk/rtp_analysis.c
+++ b/ui/gtk/rtp_analysis.c
@@ -3769,7 +3769,7 @@ rtp_analysis(address *src_fwd,
/* file names for storing sound data */
- fd = create_tempfile(&tempname, "wireshark_rtp_f");
+ fd = create_tempfile(&tempname, "wireshark_rtp_f", NULL);
if (fd < 0) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Can't create temporary file for RTP analysis:\n%s.",
@@ -3779,7 +3779,7 @@ rtp_analysis(address *src_fwd,
}
user_data->f_tempname = g_strdup(tempname);
ws_close(fd);
- fd = create_tempfile(&tempname, "wireshark_rtp_r");
+ fd = create_tempfile(&tempname, "wireshark_rtp_r", NULL);
if (fd < 0) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Can't create temporary file for RTP analysis:\n%s.",
diff --git a/wiretap/file_access.c b/wiretap/file_access.c
index f138376428..f5ba60dc56 100644
--- a/wiretap/file_access.c
+++ b/wiretap/file_access.c
@@ -2289,7 +2289,7 @@ wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx,
return NULL;
/* Choose a random name for the file */
- fd = create_tempfile(&tmpname, pfx);
+ fd = create_tempfile(&tmpname, pfx, ".pcapng");
if (fd == -1) {
*err = errno;
g_free(wdh);
diff --git a/wiretap/nettrace_3gpp_32_423.c b/wiretap/nettrace_3gpp_32_423.c
index 9fd47fbc1d..305a4e4f45 100644
--- a/wiretap/nettrace_3gpp_32_423.c
+++ b/wiretap/nettrace_3gpp_32_423.c
@@ -751,7 +751,7 @@ create_temp_pcapng_file(wtap *wth, int *err, gchar **err_info, nettrace_3gpp_32_
exported_pdu_info.dst_port = 0;
exported_pdu_info.proto_col_str = NULL;
- import_file_fd = create_tempfile(&(file_info->tmpname), "Wireshark_PDU_");
+ import_file_fd = create_tempfile(&(file_info->tmpname), "Wireshark_PDU_", NULL);
/* Now open a file and dump to it */
/* Create data for SHB */
diff --git a/wsutil/tempfile.c b/wsutil/tempfile.c
index 2835735006..ed6dd5b8d3 100644
--- a/wsutil/tempfile.c
+++ b/wsutil/tempfile.c
@@ -44,36 +44,40 @@
#define INITIAL_PATH_SIZE 128
#define TMP_FILE_SUFFIX "XXXXXX"
-#ifndef HAVE_MKSTEMP
+#ifndef HAVE_MKSTEMPS
/* Generate a unique temporary file name from TEMPLATE.
- The last six characters of TEMPLATE must be TMP_FILE_SUFFIX;
- they are replaced with a string that makes the filename unique.
+ The last six characters before the suffix length of TEMPLATE
+ must be TMP_FILE_SUFFIX; they are replaced with a string that
+ makes the filename unique.
Returns a file descriptor open on the file for reading and writing. */
static int
-mkstemp (char *path_template)
+mkstemps(char *path_template, int suffixlen)
{
static const char letters[]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ char uniqueness[6];
size_t len;
size_t i;
len = strlen (path_template);
- if (len < 6 || strcmp (&path_template[len - 6], TMP_FILE_SUFFIX))
+ if (len < 6 || strncmp (&path_template[len - 6 - suffixlen], TMP_FILE_SUFFIX, 6))
{
__set_errno (EINVAL);
return -1;
}
- if (g_snprintf (&path_template[len - 5], 6, "%.5u",
+ if (g_snprintf (uniqueness, 6, "%.5u",
(unsigned int) ws_getpid () % 100000) != 5)
/* Inconceivable lossage. */
return -1;
+ memcpy(&path_template[len - 5 - suffixlen], uniqueness, 5);
+
for (i = 0; i < sizeof (letters); ++i)
{
int fd;
- path_template[len - 6] = letters[i];
+ path_template[len - 6 - suffixlen] = letters[i];
fd = ws_open (path_template, O_RDWR|O_BINARY|O_CREAT|O_EXCL, 0600);
if (fd >= 0)
@@ -86,7 +90,7 @@ mkstemp (char *path_template)
return -1;
}
-#endif /* HAVE_MKSTEMP */
+#endif /* HAVE_MKSTEMPS */
#ifndef HAVE_MKDTEMP
/* Generate a unique temporary directory name from TEMPLATE.
@@ -149,13 +153,12 @@ char *get_tempfile_path(const char *filename)
* @param namebuf If not NULL, receives the full path of the temp file.
* Should NOT be freed.
* @param pfx A prefix for the temporary file.
- * @return The file descriptor of the new tempfile, from mkstemp().
- * @todo Switch from mkstemp() to something like mkstemps(), so the caller
- * can optionally indicate that part of the pfx is actually a suffix,
- * such as "pcap" or "pcapng".
+ * @param sfx [in] A file extension for the temporary file. NULL can be passed
+ * if no file extension is needed
+ * @return The file descriptor of the new tempfile, from mkstemps().
*/
int
-create_tempfile(char **namebuf, const char *pfx)
+create_tempfile(char **namebuf, const char *pfx, const char *sfx)
{
static struct _tf {
char *path;
@@ -203,7 +206,7 @@ create_tempfile(char **namebuf, const char *pfx)
current_time = time(NULL);
strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", localtime(&current_time));
sep[0] = G_DIR_SEPARATOR;
- tmp_file = g_strconcat(tmp_dir, sep, safe_pfx, "_", timestr, "_", TMP_FILE_SUFFIX, NULL);
+ tmp_file = g_strconcat(tmp_dir, sep, safe_pfx, "_", timestr, "_", TMP_FILE_SUFFIX, sfx, NULL);
g_free(safe_pfx);
if (strlen(tmp_file) > tf[idx].len) {
tf[idx].len = strlen(tmp_file) + 1;
@@ -215,14 +218,14 @@ create_tempfile(char **namebuf, const char *pfx)
if (namebuf) {
*namebuf = tf[idx].path;
}
- /* The Single UNIX Specification doesn't say that "mkstemp()"
+ /* The Single UNIX Specification doesn't say that "mkstemps()"
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 = ws_umask(0077);
- fd = mkstemp(tf[idx].path);
+ fd = mkstemps(tf[idx].path, sfx ? strlen(sfx) : 0);
ws_umask(old_umask);
return fd;
}
diff --git a/wsutil/tempfile.h b/wsutil/tempfile.h
index f595632f25..1dca2dfa13 100644
--- a/wsutil/tempfile.h
+++ b/wsutil/tempfile.h
@@ -50,9 +50,11 @@ WS_DLL_PUBLIC char *get_tempfile_path(const char *filename);
* @param namebuf [in,out] If not NULL, receives the full path of the temp file.
* Must NOT be freed.
* @param pfx [in] A prefix for the temporary file.
- * @return The file descriptor of the new tempfile, from mkstemp().
+ * @param sfx [in] A file extension for the temporary file. NULL can be passed
+ * if no file extension is needed
+ * @return The file descriptor of the new tempfile, from mkstemps().
*/
-WS_DLL_PUBLIC int create_tempfile(char **namebuf, const char *pfx);
+WS_DLL_PUBLIC int create_tempfile(char **namebuf, const char *pfx, const char *sfx);
/**
* Create a directory with the given prefix (e.g. "wireshark"). The path