GTK UI: remove eo_saveable_pathname in favor of eo_massage_str

The function had several deficiencies:

- When "" is passed as the filename, the function returns a null
  pointer (due to the quirky behavior of g_strsplit_set), which causes a
  segfault when it's dereferenced later. I'm not sure what the correct
  return should be, but it shouldn't be NULL.

- It leaks memory. (The array of strings returned by
  g_strsplit_set are never freed.)

- It only strips out backslashes. That is not the only character that
  is disallowed in filenames, even on windows.

- The functionality is already provided by eo_massage_str and
  it does a more complete job of it.

Change-Id: I4d9eab7506048c5d04de8f163b8af1e3f67c163d
Reviewed-on: https://code.wireshark.org/review/7996
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
David Creswick 2015-04-05 19:13:57 -05:00 committed by Gerald Combs
parent fa04dfdd77
commit b5ef92efc0
1 changed files with 6 additions and 29 deletions

View File

@ -129,26 +129,6 @@ eo_win_destroy_cb(GtkWindow *win _U_, gpointer data)
if (eo_protocoldata_reset != NULL) eo_protocoldata_reset();
}
static gchar *eo_saveable_pathname(gchar *filename) {
gchar **splitted_pathname;
gchar *auxstring, *saveable_pathname;
guint nparts,i;
saveable_pathname = NULL;
splitted_pathname = g_strsplit_set(filename,"\\",-1);
nparts = g_strv_length(splitted_pathname);
if (nparts>0) {
saveable_pathname=g_strdup(splitted_pathname[0]);
}
for (i=1;i<nparts;i++) {
auxstring = g_strconcat(saveable_pathname,"__",splitted_pathname[i],NULL);
g_free(saveable_pathname);
saveable_pathname = auxstring;
}
return saveable_pathname;
}
static char *
gtk_eo_save_object_as_file(export_object_list_t *object_list, char *auxfilename)
{
@ -178,7 +158,7 @@ eo_save_clicked_cb(GtkWidget *widget _U_, gpointer arg)
{
export_object_list_t *object_list = (export_object_list_t *)arg;
export_object_entry_t *entry;
gchar *auxfilename = NULL;
GString *safe_filename = NULL;
char *pathname;
entry =(export_object_entry_t *) g_slist_nth_data(object_list->entries,
@ -189,13 +169,13 @@ eo_save_clicked_cb(GtkWidget *widget _U_, gpointer arg)
return;
}
auxfilename = eo_saveable_pathname(entry->filename);
safe_filename = eo_massage_str(entry->filename, 256, 0);
/*
* Loop until the user either selects a file or gives up.
*/
for (;;) {
pathname = gtk_eo_save_object_as_file(object_list, auxfilename);
pathname = gtk_eo_save_object_as_file(object_list, safe_filename->str);
if (pathname == NULL) {
/* User gave up. */
break;
@ -210,7 +190,7 @@ eo_save_clicked_cb(GtkWidget *widget _U_, gpointer arg)
g_free(pathname);
}
g_free(auxfilename);
g_string_free(safe_filename, TRUE);
}
#define MAXFILELEN 255
@ -225,7 +205,6 @@ eo_save_all_clicked_cb(GtkWidget *widget _U_, gpointer arg)
gboolean all_saved = TRUE;
gchar *save_in_path;
GString *safe_filename;
gchar *auxfilename = NULL;
int count = 0;
save_in_w = file_selection_new("Wireshark: Save All Objects In ...",
@ -241,12 +220,10 @@ eo_save_all_clicked_cb(GtkWidget *widget _U_, gpointer arg)
do {
g_free(save_as_fullpath);
if (entry->filename) {
auxfilename = eo_saveable_pathname(entry->filename);
safe_filename = eo_massage_str(auxfilename,
safe_filename = eo_massage_str(entry->filename,
MAXFILELEN - strlen(save_in_path), count);
g_free(auxfilename);
} else {
char generic_name[256];
char generic_name[MAXFILELEN+1];
const char *ext;
ext = ct2ext(entry->content_type);
g_snprintf(generic_name, sizeof(generic_name),