aboutsummaryrefslogtreecommitdiffstats
path: root/tempfile.c
diff options
context:
space:
mode:
authorEvan Huus <eapache@gmail.com>2013-01-26 15:51:01 +0000
committerEvan Huus <eapache@gmail.com>2013-01-26 15:51:01 +0000
commit822405e4d9367fc5cf213f701862b273388d58e0 (patch)
treecda463d2145ce809172e5c3b6127196b52f6c6bb /tempfile.c
parentfbf1970b066ef2fd9f078b82a5d950d088dd4121 (diff)
The const was important, take a copy of the suffix to sanitize instead.
svn path=/trunk/; revision=47300
Diffstat (limited to 'tempfile.c')
-rw-r--r--tempfile.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/tempfile.c b/tempfile.c
index 73aa47d9fb..2fab0df257 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -160,7 +160,7 @@ mkdtemp (char *template)
* such as "pcap" or "pcapng".
*/
int
-create_tempfile(char **namebuf, char *pfx)
+create_tempfile(char **namebuf, const char *pfx)
{
static struct _tf {
char *path;
@@ -174,6 +174,7 @@ create_tempfile(char **namebuf, char *pfx)
time_t current_time;
char timestr[14 + 1];
gchar *tmp_file;
+ gchar *safe_pfx;
gchar sep[2] = {0, 0};
/* The characters in "delimiters" come from:
@@ -186,7 +187,8 @@ create_tempfile(char **namebuf, char *pfx)
"\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
/* Sanitize the pfx to resolve bug 7877 */
- pfx = g_strdelimit(pfx, delimiters, '-');
+ safe_pfx = g_strdup(pfx);
+ safe_pfx = g_strdelimit(safe_pfx, delimiters, '-');
idx = (idx + 1) % MAX_TEMPFILES;
@@ -209,7 +211,8 @@ create_tempfile(char **namebuf, 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, pfx, "_", timestr, "_", TMP_FILE_SUFFIX, NULL);
+ tmp_file = g_strconcat(tmp_dir, sep, safe_pfx, "_", timestr, "_", TMP_FILE_SUFFIX, NULL);
+ g_free(safe_pfx);
if (strlen(tmp_file) > tf[idx].len) {
tf[idx].len = (int)strlen(tmp_file) + 1;
tf[idx].path = (char *)g_realloc(tf[idx].path, tf[idx].len);