The const was important, take a copy of the suffix to sanitize instead.

svn path=/trunk/; revision=47300
This commit is contained in:
Evan Huus 2013-01-26 15:51:01 +00:00
parent fbf1970b06
commit 822405e4d9
2 changed files with 7 additions and 4 deletions

View File

@ -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);

View File

@ -43,7 +43,7 @@ extern "C" {
* @param pfx A prefix for the temporary file.
* @return The file descriptor of the new tempfile, from mkstemp().
*/
int create_tempfile(char **namebuf, char *pfx);
int create_tempfile(char **namebuf, const char *pfx);
/**
* Create a directory with the given prefix (e.g. "wireshark"). The path