aboutsummaryrefslogtreecommitdiffstats
path: root/tempfile.c
diff options
context:
space:
mode:
authorChris Maynard <Christopher.Maynard@GTECH.COM>2013-01-26 15:41:16 +0000
committerChris Maynard <Christopher.Maynard@GTECH.COM>2013-01-26 15:41:16 +0000
commit036906465c899cf281e83b6b607ea8c6399c54cd (patch)
tree923955e81f4a847f5956da5ae4aaada10e7d0c0e /tempfile.c
parenta18bdb19df6816feebe3085cd9d5f000351ed1a8 (diff)
Replace disallowed filename characters to '-'.
Fixes https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7877 #BACKPORT(1.8, 1.6) svn path=/trunk/; revision=47298
Diffstat (limited to 'tempfile.c')
-rw-r--r--tempfile.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/tempfile.c b/tempfile.c
index 9c3fd6f241..73aa47d9fb 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -150,14 +150,17 @@ mkdtemp (char *template)
/**
* Create a tempfile with the given prefix (e.g. "wireshark").
- *
+ *
* @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".
*/
int
-create_tempfile(char **namebuf, const char *pfx)
+create_tempfile(char **namebuf, char *pfx)
{
static struct _tf {
char *path;
@@ -173,8 +176,20 @@ create_tempfile(char **namebuf, const char *pfx)
gchar *tmp_file;
gchar sep[2] = {0, 0};
+ /* The characters in "delimiters" come from:
+ * http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx.
+ * Add to the list as necessary for other OS's.
+ */
+ const gchar *delimiters = "<>:\"/\\|?*"
+ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a"
+ "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
+ "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
+
+ /* Sanitize the pfx to resolve bug 7877 */
+ pfx = g_strdelimit(pfx, delimiters, '-');
+
idx = (idx + 1) % MAX_TEMPFILES;
-
+
/*
* Allocate the buffer if it's not already allocated.
*/
@@ -220,8 +235,8 @@ create_tempfile(char **namebuf, const char *pfx)
/**
* Create a directory with the given prefix (e.g. "wireshark"). The path
* is created using g_get_tmp_dir and mkdtemp.
- *
- * @param namebuf
+ *
+ * @param namebuf
* @param pfx A prefix for the temporary directory.
* @return The temporary directory path on success, or NULL on failure.
* Must NOT be freed.
@@ -235,7 +250,7 @@ create_tempdir(char **namebuf, const char *pfx)
const char *tmp_dir;
idx = (idx + 1) % 3;
-
+
/*
* Allocate the buffer if it's not already allocated.
*/