From c8d2cd3cb51a4144b38bfaf82482bd30d7df1064 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sat, 9 Apr 2011 04:33:26 +0000 Subject: [PATCH] In packet_list_dissect_and_cache_record(), set the columns to *something* if we get an error reading the packet from the capture file, rather than leaving them as null (which will cause a crash). svn path=/trunk/; revision=36527 --- epan/column-utils.c | 51 +++++++++++++++++++++++++++++++++++++++++ epan/column-utils.h | 8 +++++++ epan/libwireshark.def | 1 + gtk/packet_list_store.c | 29 +++++++++++++++++++++-- 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/epan/column-utils.c b/epan/column-utils.c index 83e60718e9..17ee2ad18e 100644 --- a/epan/column-utils.c +++ b/epan/column-utils.c @@ -1652,6 +1652,57 @@ col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fi } } +/* + * Fill in columns if we got an error reading the packet. + * We set most columns to "???", and set the Info column to an error + * message. + */ +void +col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col_exprs, const gboolean fill_fd_colums) +{ + int i; + + if (!cinfo) + return; + + for (i = 0; i < cinfo->num_cols; i++) { + switch (cinfo->col_fmt[i]) { + + case COL_NUMBER: + case COL_CLS_TIME: + case COL_ABS_TIME: + case COL_ABS_DATE_TIME: + case COL_REL_TIME: + case COL_DELTA_TIME: + case COL_DELTA_TIME_DIS: + case COL_PACKET_LENGTH: + case COL_CUMULATIVE_BYTES: + if (fill_fd_colums) + col_fill_in_frame_data(fdata, cinfo, i, fill_col_exprs); + break; + + case COL_INFO: + /* XXX - say more than this */ + cinfo->col_data[i] = "Read error"; + break; + + case NUM_COL_FMTS: /* keep compiler happy - shouldn't get here */ + g_assert_not_reached(); + break; + default: + if (cinfo->col_fmt[i] >= NUM_COL_FMTS) { + g_assert_not_reached(); + } + /* + * No dissection was done, and these columns are set as the + * result of the dissection, so.... + */ + cinfo->col_data[i] = "???"; + break; + } + } +} + #if 0 XXX this needs more rework? /* --------------------------- */ diff --git a/epan/column-utils.h b/epan/column-utils.h index 37148a833a..7e99094e23 100644 --- a/epan/column-utils.h +++ b/epan/column-utils.h @@ -70,6 +70,14 @@ extern void col_fill_in_frame_data(const frame_data *fd, column_info *cinfo, con */ extern void col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fill_fd_colums); +/** Fill in columns if we got an error reading the packet. + * We set most columns to "???", and set the Info column to an error + * message. + * + * Internal, don't use this in dissectors! + */ +extern void col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col_exprs, const gboolean fill_fd_colums); + /* Utility routines used by packet*.c */ /** Are the columns writable? diff --git a/epan/libwireshark.def b/epan/libwireshark.def index fe47927800..08924665db 100644 --- a/epan/libwireshark.def +++ b/epan/libwireshark.def @@ -87,6 +87,7 @@ col_based_on_frame_data col_clear col_custom_prime_edt col_fill_in +col_fill_in_error col_fill_in_frame_data col_format_desc col_format_to_string diff --git a/gtk/packet_list_store.c b/gtk/packet_list_store.c index 2bb4abe1a3..20a9a2229f 100644 --- a/gtk/packet_list_store.c +++ b/gtk/packet_list_store.c @@ -1125,8 +1125,33 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord * else cinfo = NULL; - if (!cf_read_frame_r(&cfile, fdata, &pseudo_header, pd)) + if (!cf_read_frame_r(&cfile, fdata, &pseudo_header, pd)) { + /* + * Error reading the frame. + * + * Don't set the color filter for now (we might want + * to colorize it in some fashion to warn that the + * row couldn't be filled in or colorized), and + * set the columns to placeholder values, except + * for the Info column, where we'll put in an + * error message. + */ + if (dissect_columns) { + col_fill_in_error(cinfo, fdata, FALSE, FALSE /* fill_fd_columns */); + + for(col = 0; col < cinfo->num_cols; ++col) { + /* Skip columns based on frame_data because we already store those. */ + if (!col_based_on_frame_data(cinfo, col)) + packet_list_change_record(packet_list, record->physical_pos, col, cinfo); + } + record->columnized = TRUE; + } + if (dissect_color) { + fdata->color_filter = NULL; + record->colorized = TRUE; + } return; /* error reading the frame */ + } create_proto_tree = (color_filters_used() && dissect_color) || (have_custom_cols(cinfo) && dissect_columns); @@ -1150,7 +1175,7 @@ packet_list_dissect_and_cache_record(PacketList *packet_list, PacketListRecord * epan_dissect_fill_in_columns(&edt, FALSE, FALSE /* fill_fd_columns */); for(col = 0; col < cinfo->num_cols; ++col) { - /* Skip columns based om frame_data because we already store those. */ + /* Skip columns based on frame_data because we already store those. */ if (!col_based_on_frame_data(cinfo, col)) packet_list_change_record(packet_list, record->physical_pos, col, cinfo); }