aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEldon Stegall <wireshark-gerrit@eldondev.com>2017-10-17 14:55:52 +0000
committerAnders Broman <a.broman58@gmail.com>2017-10-23 04:42:51 +0000
commitc7918da8a6b28fc515d273c16a9ffca2a4b9e119 (patch)
tree60d23bbba857826744cc29485d432f46e3bbe296
parentb74af851471687e258fa7624a498981b77ebdba6 (diff)
Improve http object export for URLs with long extensions
This allows the export of objects with extensions that may be longer than the allowed file name of an export (due to underlying filesystem, etc). The extension detection mechanism previously preserved everything in the file name after the final ".", but in some cases (especially with long query strings) this would exceed the allowed maximum file length, and simply refuse to export the object. Now, if the length of the extension and duplicate number is longer than the allowable file length, the extension is ignored, and the entire string is truncated to allow an acceptable export filename. Bug: 14130 Change-Id: I6fa0281519d031c07a9ac621002ac328f34f54cc Reviewed-on: https://code.wireshark.org/review/23960 Reviewed-by: Michael Mann <mmann78@netscape.net> Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--epan/export_object.c35
-rw-r--r--ui/gtk/export_object_dlg.c2
-rw-r--r--ui/qt/export_object_dialog.cpp4
3 files changed, 16 insertions, 25 deletions
diff --git a/epan/export_object.c b/epan/export_object.c
index bdcf4ca..eb4fd48 100644
--- a/epan/export_object.c
+++ b/epan/export_object.c
@@ -90,27 +90,28 @@ void eo_iterate_tables(wmem_foreach_func func, gpointer user_data)
wmem_tree_foreach(registered_eo_tables, func, user_data);
}
-static GString *eo_rename(GString *gstr, int dupn)
+static GString *eo_rename(GString *gstr, gsize maxlen, int dupn)
{
GString *gstr_tmp;
gchar *tmp_ptr;
GString *ext_str;
- gstr_tmp = g_string_new("(");
- g_string_append_printf (gstr_tmp, "%d)", dupn);
- if ( (tmp_ptr = strrchr(gstr->str, '.')) != NULL ) {
+ gstr_tmp = g_string_new("");
+ if (dupn != 0) {
+ g_string_append_printf (gstr_tmp, "(%d)", dupn);
+ }
+ if ( (tmp_ptr = strrchr(gstr->str, '.')) != NULL && ((ext_str = g_string_new(tmp_ptr))->len + strlen(gstr_tmp->str) < maxlen) ) {
/* Retain the extension */
- ext_str = g_string_new(tmp_ptr);
gstr = g_string_truncate(gstr, gstr->len - ext_str->len);
- if ( gstr->len >= (EXPORT_OBJECT_MAXFILELEN - (strlen(gstr_tmp->str) + ext_str->len)) )
- gstr = g_string_truncate(gstr, EXPORT_OBJECT_MAXFILELEN - (strlen(gstr_tmp->str) + ext_str->len));
+ if ( gstr->len >= (maxlen - (strlen(gstr_tmp->str) + ext_str->len)) )
+ gstr = g_string_truncate(gstr, maxlen - (strlen(gstr_tmp->str) + ext_str->len));
gstr = g_string_append(gstr, gstr_tmp->str);
gstr = g_string_append(gstr, ext_str->str);
g_string_free(ext_str, TRUE);
}
else {
- if ( gstr->len >= (EXPORT_OBJECT_MAXFILELEN - strlen(gstr_tmp->str)) )
- gstr = g_string_truncate(gstr, EXPORT_OBJECT_MAXFILELEN - strlen(gstr_tmp->str));
+ if ( gstr->len >= (maxlen - strlen(gstr_tmp->str)) )
+ gstr = g_string_truncate(gstr, maxlen - strlen(gstr_tmp->str));
gstr = g_string_append(gstr, gstr_tmp->str);
}
g_string_free(gstr_tmp, TRUE);
@@ -130,7 +131,6 @@ eo_massage_str(const gchar *in_str, gsize maxlen, int dupn)
"\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
"\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
GString *out_str;
- GString *ext_str;
out_str = g_string_new("");
@@ -141,19 +141,8 @@ eo_massage_str(const gchar *in_str, gsize maxlen, int dupn)
in_str = tmp_ptr + 1;
}
out_str = g_string_append(out_str, in_str);
- if ( out_str->len > maxlen ) {
- if ( (tmp_ptr = strrchr(out_str->str, '.')) != NULL ) {
- /* Retain the extension */
- ext_str = g_string_new(tmp_ptr);
- out_str = g_string_truncate(out_str, maxlen - ext_str->len);
- out_str = g_string_append(out_str, ext_str->str);
- g_string_free(ext_str, TRUE);
- }
- else
- out_str = g_string_truncate(out_str, maxlen);
- }
- if ( dupn != 0 )
- out_str = eo_rename(out_str, dupn);
+ if ( dupn != 0 || out_str->len > maxlen )
+ out_str = eo_rename(out_str, maxlen, dupn);
return out_str;
}
diff --git a/ui/gtk/export_object_dlg.c b/ui/gtk/export_object_dlg.c
index ba7ce9c..ee07838 100644
--- a/ui/gtk/export_object_dlg.c
+++ b/ui/gtk/export_object_dlg.c
@@ -160,7 +160,7 @@ eo_save_clicked_cb(GtkWidget *widget _U_, gpointer arg)
return;
}
- safe_filename = eo_massage_str(entry->filename, 256, 0);
+ safe_filename = eo_massage_str(entry->filename, EXPORT_OBJECT_MAXFILELEN, 0);
/*
* Loop until the user either selects a file or gives up.
diff --git a/ui/qt/export_object_dialog.cpp b/ui/qt/export_object_dialog.cpp
index d5b60af..4d3d3dc 100644
--- a/ui/qt/export_object_dialog.cpp
+++ b/ui/qt/export_object_dialog.cpp
@@ -312,8 +312,10 @@ void ExportObjectDialog::saveCurrentEntry()
return;
}
+ GString *safe_filename = eo_massage_str(entry->filename, EXPORT_OBJECT_MAXFILELEN-path.canonicalPath().length(), 0);
file_name = QFileDialog::getSaveFileName(this, wsApp->windowTitleString(tr("Save Object As" UTF8_HORIZONTAL_ELLIPSIS)),
- path.filePath(entry->filename));
+ safe_filename->str);
+ g_string_free(safe_filename, TRUE);
if (file_name.length() > 0) {
eo_save_entry(file_name.toUtf8().constData(), entry, TRUE);