From Kovarththanan Rajaratnam: Fixes for bug #3536

(plus some additional changes by me).

Handle BASE_RANGE_STRING display types properly

We always treat header field info strings as value_string's undiscriminated.
However, if the header field info display is marked as BASE_RANGE_STRING, we
need to treat them as range_string's. This wasn't properly handled in the
filter expression dialog and in the filter toolbar which would cause a crash
upon referencing any fields marked as BASE_RANGE_STRING.


svn path=/trunk/; revision=28931
This commit is contained in:
Bill Meier 2009-07-03 01:11:23 +00:00
parent 5631122d1d
commit 174ce5633c
2 changed files with 35 additions and 32 deletions

View File

@ -152,7 +152,6 @@ mk_fvalue_from_val_string(header_field_info *hfinfo, char *s)
{
static const true_false_string default_tf = { "True", "False" };
const true_false_string *tf = &default_tf;
const value_string *vals;
/* Early return? */
switch(hfinfo->type) {
@ -177,7 +176,7 @@ mk_fvalue_from_val_string(header_field_info *hfinfo, char *s)
case FT_PCRE:
case FT_GUID:
case FT_OID:
return FALSE;
return NULL;
case FT_BOOLEAN:
case FT_FRAMENUM:
@ -223,19 +222,26 @@ mk_fvalue_from_val_string(header_field_info *hfinfo, char *s)
if (!hfinfo->strings) {
dfilter_fail("%s cannot accept strings as values.",
hfinfo->abbrev);
return FALSE;
return NULL;
}
vals = hfinfo->strings;
while (vals->strptr != NULL) {
if (g_ascii_strcasecmp(s, vals->strptr) == 0) {
return mk_uint32_fvalue(vals->value);
}
vals++;
if (hfinfo->display & BASE_RANGE_STRING) {
dfilter_fail("\"%s\" cannot accept [range] strings as values.",
hfinfo->abbrev);
return NULL;
}
dfilter_fail("\"%s\" cannot be found among the possible values for %s.",
s, hfinfo->abbrev);
return FALSE;
else {
const value_string *vals = hfinfo->strings;
while (vals->strptr != NULL) {
if (g_ascii_strcasecmp(s, vals->strptr) == 0) {
return mk_uint32_fvalue(vals->value);
}
vals++;
}
dfilter_fail("\"%s\" cannot be found among the possible values for %s.",
s, hfinfo->abbrev);
}
return NULL;
}
static gboolean

View File

@ -189,13 +189,12 @@ field_select_row_cb(GtkTreeSelection *sel, gpointer tree)
case FT_INT24:
case FT_INT32:
/*
* If this has a value_string table associated with it,
* fill up the list of values, otherwise clear the list
* of values.
* If this has a value_string table (not a range_string table) associated with it,
* fill up the list of values, otherwise clear the list of values.
*/
if (hfinfo->strings != NULL) {
build_enum_values(value_list_scrolled_win, value_list,
hfinfo->strings);
/* XXX: ToDo: Implement "range-string" filter ? */
if ((hfinfo->strings != NULL) & !(hfinfo->display & BASE_RANGE_STRING)) {
build_enum_values(value_list_scrolled_win, value_list, hfinfo->strings);
} else
gtk_list_store_clear(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(value_list))));
break;
@ -425,7 +424,7 @@ static void
display_value_fields(header_field_info *hfinfo, gboolean is_comparison,
GtkWidget *value_label, GtkWidget *value_entry,
GtkWidget *value_list_label,
GtkWidget *value_list _U_,
GtkWidget *value_list _U_,
GtkWidget *value_list_scrolled_win, GtkWidget *range_label,
GtkWidget *range_entry)
{
@ -484,7 +483,7 @@ display_value_fields(header_field_info *hfinfo, gboolean is_comparison,
case FT_INT16:
case FT_INT24:
case FT_INT32:
if (hfinfo->strings != NULL) {
if ((hfinfo->strings != NULL) && !(hfinfo->display & BASE_RANGE_STRING)) {
/*
* We have a list of values to show.
*/
@ -539,7 +538,7 @@ value_list_sel_cb(GtkTreeSelection *sel, gpointer value_entry_arg)
header_field_info *hfinfo = g_object_get_data(G_OBJECT(window),
E_DFILTER_EXPR_CURRENT_VAR_KEY);
const value_string *value = NULL;
gchar *value_string = NULL;
gchar *value_display_string = NULL;
if (!gtk_tree_selection_get_selected(sel, &model, &iter))
return;
@ -557,16 +556,16 @@ value_list_sel_cb(GtkTreeSelection *sel, gpointer value_entry_arg)
* testing for "false".
*/
if (value != NULL)
value_string = g_strdup("1");
value_display_string = g_strdup("1");
else
value_string = g_strdup("0");
value_display_string = g_strdup("0");
} else {
/*
* Numeric type; get the value corresponding to the
* selected item, and display it in the base for this
* field.
*/
switch (hfinfo->display) {
switch ((hfinfo->display) & BASE_STRUCTURE_RESET) {
case BASE_NONE:
case BASE_DEC:
@ -576,14 +575,14 @@ value_list_sel_cb(GtkTreeSelection *sel, gpointer value_entry_arg)
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
value_string = g_strdup_printf("%u", value->value);
value_display_string = g_strdup_printf("%u", value->value);
break;
case FT_INT8:
case FT_INT16:
case FT_INT24:
case FT_INT32:
value_string = g_strdup_printf("%d", value->value);
value_display_string = g_strdup_printf("%d", value->value);
break;
default:
@ -592,11 +591,11 @@ value_list_sel_cb(GtkTreeSelection *sel, gpointer value_entry_arg)
break;
case BASE_HEX:
value_string = g_strdup_printf("0x%x", value->value);
value_display_string = g_strdup_printf("0x%x", value->value);
break;
case BASE_OCT:
value_string = g_strdup_printf("%#o", value->value);
value_display_string = g_strdup_printf("%#o", value->value);
break;
default:
@ -604,8 +603,8 @@ value_list_sel_cb(GtkTreeSelection *sel, gpointer value_entry_arg)
}
}
gtk_entry_set_text(GTK_ENTRY(value_entry), value_string);
g_free (value_string);
gtk_entry_set_text(GTK_ENTRY(value_entry), value_display_string);
g_free (value_display_string);
}
static void
@ -1132,7 +1131,6 @@ dfilter_expr_dlg_new(GtkWidget *filter_te)
g_snprintf(str, TAG_STRING_LEN, "%s - %s",
proto_get_protocol_short_name(protocol),
proto_get_protocol_long_name(protocol));
str[TAG_STRING_LEN]='\0';
strp=str;
hfinfo = proto_registrar_get_nth(i);
@ -1153,7 +1151,6 @@ dfilter_expr_dlg_new(GtkWidget *filter_te)
g_snprintf(str, TAG_STRING_LEN, "%s - %s", hfinfo->abbrev,
hfinfo->name);
}
str[TAG_STRING_LEN]='\0';
gtk_tree_store_append(store, &child_iter, &iter);
gtk_tree_store_set(store, &child_iter, 0, strp, 1, hfinfo, -1);
}