diff --git a/asn1/kerberos/packet-kerberos-template.c b/asn1/kerberos/packet-kerberos-template.c index bdbaad1bb0..814f8a83d1 100644 --- a/asn1/kerberos/packet-kerberos-template.c +++ b/asn1/kerberos/packet-kerberos-template.c @@ -1432,7 +1432,7 @@ dissect_kerberos_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, TRY { offset=dissect_kerberos_Applications(FALSE, tvb, 0, &asn1_ctx , tree, /* hf_index */ -1); - } CATCH_ALL { + } CATCH_BOUNDS_ERRORS { pinfo->private_data=saved_private_data; RETHROW; } ENDTRY; diff --git a/asn1/ldap/packet-ldap-template.c b/asn1/ldap/packet-ldap-template.c index 328ffbbdbc..4c4d151de8 100644 --- a/asn1/ldap/packet-ldap-template.c +++ b/asn1/ldap/packet-ldap-template.c @@ -96,7 +96,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/asn1/t124/packet-t124-template.c b/asn1/t124/packet-t124-template.c index 35ac9930cd..f0b5418901 100644 --- a/asn1/t124/packet-t124-template.c +++ b/asn1/t124/packet-t124-template.c @@ -163,7 +163,7 @@ dissect_t124_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, vo */ TRY { (void) dissect_per_sequence(tvb, 0, &asn1_ctx, NULL, -1, -1, t124Heur_sequence); - } CATCH2(BoundsError, ReportedBoundsError) { + } CATCH_BOUNDS_ERRORS { failed = TRUE; } ENDTRY; diff --git a/asn1/t125/packet-t125-template.c b/asn1/t125/packet-t125-template.c index 0d959c8685..f89555b224 100644 --- a/asn1/t125/packet-t125-template.c +++ b/asn1/t125/packet-t125-template.c @@ -109,7 +109,7 @@ dissect_t125_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, vo TRY { /* could be BER */ get_ber_identifier(tvb, 0, &ber_class, &pc, &tag); - } CATCH2(BoundsError, ReportedBoundsError) { + } CATCH_BOUNDS_ERRORS { failed = TRUE; } ENDTRY; @@ -126,7 +126,7 @@ dissect_t125_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, vo dissect_per_constrained_integer(tvb, 0, &asn1_ctx, NULL, hf_t125_heur, 0, 42, &choice_index, FALSE); - } CATCH2(BoundsError, ReportedBoundsError) { + } CATCH_BOUNDS_ERRORS { failed = TRUE; } ENDTRY; diff --git a/asn1/tcap/packet-tcap-template.c b/asn1/tcap/packet-tcap-template.c index ba0cebd0ed..b3de566382 100644 --- a/asn1/tcap/packet-tcap-template.c +++ b/asn1/tcap/packet-tcap-template.c @@ -33,11 +33,11 @@ #include #include #include +#include #include #include "packet-ber.h" #include "packet-tcap.h" -#include "packet-frame.h" #include #define PNAME "Transaction Capabilities Application Part" diff --git a/asn1/tcap/tcap.cnf b/asn1/tcap/tcap.cnf index ae28bd5839..c32c6ae20f 100644 --- a/asn1/tcap/tcap.cnf +++ b/asn1/tcap/tcap.cnf @@ -94,11 +94,8 @@ if (!next_tvb) TRY { %(DEFAULT_BODY)s } -CATCH(BoundsError) { - RETHROW; -} -CATCH(ReportedBoundsError) { - show_reported_bounds_error(tvb, actx->pinfo, tree); +CATCH_NONFATAL_ERRORS { + show_exception(tvb, actx->pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index 86dd98568d..597d76a41b 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1440,6 +1440,7 @@ set(LIBWIRESHARK_FILES reedsolomon.c report_err.c req_resp_hdrs.c + show_exception.c sigcomp_state_hdlr.c sigcomp-udvm.c sminmpec.c diff --git a/epan/Makefile.common b/epan/Makefile.common index 67bc2e5201..3e16a37ff1 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -76,6 +76,7 @@ LIBWIRESHARK_SRC = \ reedsolomon.c \ report_err.c \ req_resp_hdrs.c \ + show_exception.c \ sigcomp_state_hdlr.c \ sigcomp-udvm.c \ sminmpec.c \ @@ -221,6 +222,7 @@ LIBWIRESHARK_INCLUDES = \ req_resp_hdrs.h \ rtp_pt.h \ sctpppids.h \ + show_exception.h \ sigcomp_state_hdlr.h \ sigcomp-udvm.h \ slab.h \ diff --git a/epan/dissectors/packet-bgp.c b/epan/dissectors/packet-bgp.c index 9e3fae02de..7d92bd7857 100644 --- a/epan/dissectors/packet-bgp.c +++ b/epan/dissectors/packet-bgp.c @@ -59,7 +59,7 @@ #include #include -#include "packet-frame.h" +#include #include #include #include @@ -3961,29 +3961,26 @@ dissect_bgp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* * Dissect the PDU. * - * Catch the ReportedBoundsError exception; if this particular message - * happens to get a ReportedBoundsError exception, that doesn't mean - * that we should stop dissecting PDUs within this frame or chunk of - * reassembled data. + * If it gets an error that means there's no point in + * dissecting any more PDUs, rethrow the exception in + * question. * - * If it gets a BoundsError, we can stop, as there's nothing more to - * see, so we just re-throw it. + * If it gets any other error, report it and continue, as that + * means that PDU got an error, but that doesn't mean we should + * stop dissecting PDUs within this frame or chunk of reassembled + * data. */ pd_save = pinfo->private_data; TRY { dissect_bgp_pdu(next_tvb, pinfo, tree, first); } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { + CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; diff --git a/epan/dissectors/packet-cisco-wids.c b/epan/dissectors/packet-cisco-wids.c index 0327cddd3f..9d6cd674b7 100644 --- a/epan/dissectors/packet-cisco-wids.c +++ b/epan/dissectors/packet-cisco-wids.c @@ -52,6 +52,7 @@ #include #include #include +#include static guint global_udp_port = 0; @@ -108,11 +109,8 @@ dissect_cwids(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) pd_save = pinfo->private_data; TRY { call_dissector(ieee80211_handle, wlan_tvb, pinfo, tree); - } CATCH2(BoundsError, ReportedBoundsError) { - - expert_add_info_format(pinfo, NULL, - PI_MALFORMED, PI_ERROR, - "Malformed or short IEEE80211 subpacket"); + } CATCH_BOUNDS_ERRORS { + show_exception(wlan_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, @@ -120,9 +118,6 @@ dissect_cwids(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) */ pinfo->private_data = pd_save; - col_append_str(pinfo->cinfo, COL_INFO, - " [Malformed or short IEEE80211 subpacket] " ); - col_set_fence(pinfo->cinfo, COL_INFO); #if 0 wlan_tvb = tvb_new_subset(tvb, offset, capturelen, capturelen); /* FIXME: Why does this throw an exception? */ diff --git a/epan/dissectors/packet-dcerpc.c b/epan/dissectors/packet-dcerpc.c index 7ccc203dab..ad9cd6ceba 100644 --- a/epan/dissectors/packet-dcerpc.c +++ b/epan/dissectors/packet-dcerpc.c @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include @@ -2587,9 +2587,17 @@ dcerpc_try_handoff(packet_info *pinfo, proto_tree *tree, plurality(remaining, "", "s")); } - } CATCH(BoundsError) { - RETHROW; - } CATCH_ALL { + } CATCH_NONFATAL_ERRORS { + /* + * Somebody threw an exception that means that there + * was a problem dissecting the payload; that means + * that a dissector was found, so we don't need to + * dissect the payload as data or update the protocol + * or info columns. + * + * Just show the exception and then drive on to show + * the authentication padding. + */ show_exception(stub_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; } @@ -2644,13 +2652,14 @@ dissect_dcerpc_verifier(tvbuff_t *tvb, packet_info *pinfo, if ((auth_fns = get_auth_subdissector_fns(auth_info->auth_level, auth_info->auth_type))) { /* - * Catch all exceptions, so that even if the verifier is bad - * or we don't have all of it, we still show the stub data. + * Catch all bounds-error exceptions, so that even if the + * verifier is bad or we don't have all of it, we still + * show the stub data. */ TRY { dissect_auth_verf(auth_tvb, pinfo, dcerpc_tree, auth_fns, hdr, auth_info); - } CATCH_ALL { + } CATCH_BOUNDS_ERRORS { show_exception(auth_tvb, pinfo, dcerpc_tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; } else { @@ -2753,7 +2762,7 @@ dissect_dcerpc_cn_auth(tvbuff_t *tvb, int stub_offset, packet_info *pinfo, include auth padding, since when NTLMSSP encryption is used, the padding is actually inside the encrypted stub */ auth_info->auth_size = hdr->auth_len + 8; - } CATCH_ALL { + } CATCH_BOUNDS_ERRORS { show_exception(tvb, pinfo, dcerpc_tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; } @@ -4592,25 +4601,24 @@ dissect_dcerpc_cn_bs_body(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * processing them. */ while (tvb_reported_length_remaining(tvb, offset) != 0) { - /* - * Catch ReportedBoundsError, so that even if the stub data is bad, - * we don't abort the full DCE RPC dissection - there might be more - * than one DCE RPC PDU in the data being dissected. - * - * If we get BoundsError, it means the frame was cut short by a - * snapshot length, so there's nothing more to dissect; just - * re-throw that exception. - */ TRY { pdu_len = 0; if (dissect_dcerpc_cn(tvb, offset, pinfo, tree, dcerpc_cn_desegment, &pdu_len)) { dcerpc_pdus++; } - } CATCH(BoundsError) { - RETHROW; - } CATCH(ReportedBoundsError) { - show_reported_bounds_error(tvb, pinfo, tree); + } CATCH_NONFATAL_ERRORS { + /* + * Somebody threw an exception that means that there + * was a problem dissecting the payload; that means + * that a dissector was found, so we don't need to + * dissect the payload as data or update the protocol + * or info columns. + * + * Just show the exception and then continue dissecting + * PDUs. + */ + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); /* * Presumably it looked enough like a DCE RPC PDU that we * dissected enough of it to throw an exception. diff --git a/epan/dissectors/packet-eth.c b/epan/dissectors/packet-eth.c index 568f1bad06..1c4fc80b5d 100644 --- a/epan/dissectors/packet-eth.c +++ b/epan/dissectors/packet-eth.c @@ -474,7 +474,7 @@ static gboolean check_is_802_2(tvbuff_t *tvb, int fcs_len) is_802_2 = FALSE; } } - CATCH2(BoundsError, ReportedBoundsError) { + CATCH_BOUNDS_ERRORS { ; /* do nothing */ } diff --git a/epan/dissectors/packet-ethertype.c b/epan/dissectors/packet-ethertype.c index b3a8dea332..142a3c0fe2 100644 --- a/epan/dissectors/packet-ethertype.c +++ b/epan/dissectors/packet-ethertype.c @@ -30,17 +30,17 @@ #include #include +#include +#include +#include #include "packet-bpq.h" #include "packet-eth.h" -#include "packet-frame.h" #include "packet-ip.h" #include "packet-ipv6.h" #include "packet-ipx.h" #include "packet-vlan.h" #include "packet-ieee8021ah.h" #include "packet-vines.h" -#include -#include static dissector_table_t ethertype_dissector_table; @@ -276,34 +276,16 @@ ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_etype, dissector_found = dissector_try_uint(ethertype_dissector_table, etype, next_tvb, pinfo, tree); } - CATCH(BoundsError) { - /* Somebody threw BoundsError, which means that: + CATCH_NONFATAL_ERRORS { + /* Somebody threw an exception that means that there + was a problem dissecting the payload; that means + that a dissector was found, so we don't need to + dissect the payload as data or update the protocol + or info columns. - 1) a dissector was found, so we don't need to - dissect the payload as data or update the - protocol or info columns; - - 2) dissecting the payload found that the packet was - cut off by a snapshot length before the end of - the payload. The trailer comes after the payload, - so *all* of the trailer is cut off, and we'll - just get another BoundsError if we add the trailer. - - Therefore, we just rethrow the exception so it gets - reported; we don't dissect the trailer or do anything - else. */ - RETHROW; - } - CATCH(OutOfMemoryError) { - RETHROW; - } - CATCH_ALL { - /* Somebody threw an exception other than BoundsError, which - means that a dissector was found, so we don't need to - dissect the payload as data or update the protocol or info - columns. We just show the exception and then drive on - to show the trailer, after noting that a dissector was - found and restoring the protocol value that was in effect + Just show the exception and then drive on to show + the trailer, after noting that a dissector was found + and restoring the protocol value that was in effect before we called the subdissector. */ show_exception(next_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index 277d0b86ad..749989f8a0 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -29,16 +29,17 @@ #include #endif - #include #include +#include #include -#include "packet-frame.h" #include #include #include #include +#include "packet-frame.h" + #include "color.h" #include "color_filters.h" @@ -81,10 +82,6 @@ static int hf_frame_pack_symbol_error = -1; static int hf_frame_wtap_encap = -1; static int hf_comments_text = -1; -static int proto_short = -1; -int proto_malformed = -1; -static int proto_unreassembled = -1; - static gint ett_frame = -1; static gint ett_flags = -1; static gint ett_comments = -1; @@ -504,10 +501,7 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) } #endif } - CATCH(OutOfMemoryError) { - RETHROW; - } - CATCH_ALL { + CATCH_BOUNDS_AND_DISSECTOR_ERRORS { show_exception(tvb, pinfo, parent_tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; @@ -560,10 +554,7 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) } #endif } - CATCH(OutOfMemoryError) { - RETHROW; - } - CATCH_ALL { + CATCH_BOUNDS_AND_DISSECTOR_ERRORS { show_exception(tvb, pinfo, parent_tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; @@ -579,99 +570,6 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) } } -void -show_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, - unsigned long exception, const char *exception_message) -{ - static const char dissector_error_nomsg[] = - "Dissector writer didn't bother saying what the error was"; - proto_item *item; - - - switch (exception) { - - case ScsiBoundsError: - col_append_str(pinfo->cinfo, COL_INFO, "[SCSI transfer limited due to allocation_length too small]"); - /*item =*/ proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0, - "SCSI transfer limited due to allocation_length too small: %s truncated]", pinfo->current_proto); - /* Don't record ScsiBoundsError exceptions as expert events - they merely - * reflect a normal SCSI condition. - * (any case where it's caused by something else is a bug). */ - /* expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Packet size limited");*/ - break; - - case BoundsError: - col_append_str(pinfo->cinfo, COL_INFO, "[Packet size limited during capture]"); - /*item =*/ proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0, - "[Packet size limited during capture: %s truncated]", pinfo->current_proto); - /* Don't record BoundsError exceptions as expert events - they merely - * reflect a capture done with a snapshot length too short to capture - * all of the packet - * (any case where it's caused by something else is a bug). */ - /* expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Packet size limited");*/ - break; - - case ReportedBoundsError: - show_reported_bounds_error(tvb, pinfo, tree); - break; - - case DissectorError: - col_append_fstr(pinfo->cinfo, COL_INFO, - "[Dissector bug, protocol %s: %s]", - pinfo->current_proto, - exception_message == NULL ? - dissector_error_nomsg : exception_message); - item = proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0, - "[Dissector bug, protocol %s: %s]", - pinfo->current_proto, - exception_message == NULL ? - dissector_error_nomsg : exception_message); - g_warning("Dissector bug, protocol %s, in packet %u: %s", - pinfo->current_proto, pinfo->fd->num, - exception_message == NULL ? - dissector_error_nomsg : exception_message); - expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, - "%s", - exception_message == NULL ? - dissector_error_nomsg : exception_message); - break; - - default: - /* XXX - we want to know, if an unknown exception passed until here, don't we? */ - g_assert_not_reached(); - } -} - -void -show_reported_bounds_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) -{ - proto_item *item; - - if (pinfo->fragmented) { - /* - * We were dissecting an unreassembled fragmented - * packet when the exception was thrown, so the - * problem isn't that the dissector expected - * something but it wasn't in the packet, the - * problem is that the dissector expected something - * but it wasn't in the fragment we dissected. - */ - col_append_fstr(pinfo->cinfo, COL_INFO, - "[Unreassembled Packet%s] ", - pinfo->noreassembly_reason); - item = proto_tree_add_protocol_format(tree, proto_unreassembled, - tvb, 0, 0, "[Unreassembled Packet%s: %s]", - pinfo->noreassembly_reason, pinfo->current_proto); - expert_add_info_format(pinfo, item, PI_REASSEMBLE, PI_WARN, "Unreassembled Packet (Exception occurred)"); - } else { - col_append_str(pinfo->cinfo, COL_INFO, - "[Malformed Packet]"); - item = proto_tree_add_protocol_format(tree, proto_malformed, - tvb, 0, 0, "[Malformed Packet: %s]", pinfo->current_proto); - expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Malformed Packet (Exception occurred)"); - } -} - void proto_register_frame(void) { @@ -895,20 +793,6 @@ proto_register_frame(void) tantamount to not doing any dissection whatsoever. */ proto_set_cant_toggle(proto_frame); - proto_short = proto_register_protocol("Short Frame", "Short frame", "short"); - proto_malformed = proto_register_protocol("Malformed Packet", - "Malformed packet", "malformed"); - proto_unreassembled = proto_register_protocol( - "Unreassembled Fragmented Packet", - "Unreassembled fragmented packet", "unreassembled"); - - /* "Short Frame", "Malformed Packet", and "Unreassembled Fragmented - Packet" aren't really protocols, they're error indications; - disabling them makes no sense. */ - proto_set_cant_toggle(proto_short); - proto_set_cant_toggle(proto_malformed); - proto_set_cant_toggle(proto_unreassembled); - /* Our preferences */ frame_module = prefs_register_protocol(proto_frame, NULL); prefs_register_bool_preference(frame_module, "show_file_off", diff --git a/epan/dissectors/packet-frame.h b/epan/dissectors/packet-frame.h index 1bebceed83..cb6edf3b4d 100644 --- a/epan/dissectors/packet-frame.h +++ b/epan/dissectors/packet-frame.h @@ -23,19 +23,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -/* - * Routine used to add an indication of an arbitrary exception to the tree. - */ -void show_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, - unsigned long exception, const char *exception_message); - -/* - * Routine used to add an indication of a ReportedBoundsError exception - * to the tree. - */ -void -show_reported_bounds_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree); - /* * Routine used to register frame end routine. The routine should only * be registred when the dissector is used in the frame, not in the @@ -44,12 +31,6 @@ show_reported_bounds_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree); void register_frame_end_routine(packet_info *pinfo, void (*func)(void)); -/* - * "Protocol" used for "malformed frame" errors (other than - * ReportedBoundsError exceptions). - */ -extern int proto_malformed; - /* * The frame dissector and the PPI dissector both use this */ diff --git a/epan/dissectors/packet-gssapi.c b/epan/dissectors/packet-gssapi.c index 0b8e3403b6..066a61af6c 100644 --- a/epan/dissectors/packet-gssapi.c +++ b/epan/dissectors/packet-gssapi.c @@ -31,17 +31,17 @@ #include #include - -#include -#include -#include #include #include #include #include #include -#include "packet-ber.h" #include +#include + +#include +#include +#include static int proto_gssapi = -1; @@ -496,15 +496,25 @@ dissect_gssapi_work(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, done: ; - } CATCH(BoundsError) { - RETHROW; - } CATCH(ReportedBoundsError) { - /* Restore the private_data structure in case one of the - * called dissectors modified it (and, due to the exception, - * was unable to restore it). + } CATCH_NONFATAL_ERRORS { + /* + * Somebody threw an exception that means that there + * was a problem dissecting the payload; that means + * that a dissector was found, so we don't need to + * dissect the payload as data or update the protocol + * or info columns. + * + * Just show the exception and then drive on to show + * the trailer, after noting that a dissector was found + * and restoring the protocol value that was in effect + * before we called the subdissector. + * + * Restore the private_data structure in case one of the + * called dissectors modified it (and, due to the exception, + * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(gss_tvb, pinfo, tree); + show_exception(gss_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; proto_item_set_len(item, return_offset); diff --git a/epan/dissectors/packet-h223.c b/epan/dissectors/packet-h223.c index 6fbcbfce50..330cdefeb0 100644 --- a/epan/dissectors/packet-h223.c +++ b/epan/dissectors/packet-h223.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include @@ -1257,26 +1257,28 @@ dissect_mux_pdu_fragment( tvbuff_t *tvb, guint32 start_offset, next_tvb = tvb_new_subset(tvb, start_offset, offset-start_offset, offset-start_offset); - - /* we catch boundserrors on the pdu so that errors on an - * individual pdu don't screw up the whole of the rest of the - * stream */ + /* + * Dissect the PDU. + * + * If it gets an error that means there's no point in dissecting + * any more PDUs, rethrow the exception in question. + * + * If it gets any other error, report it and continue, as that + * means that PDU got an error, but that doesn't mean we should + * stop dissecting PDUs within this frame or chunk of reassembled + * data. + */ pd_save = pinfo->private_data; TRY { dissect_mux_pdu( next_tvb, pinfo, start_offset, h223_tree, call_info); } - - CATCH2(BoundsError,ReportedBoundsError) { + CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - - col_append_str(pinfo->cinfo, COL_INFO, "[Malformed Packet]"); - proto_tree_add_protocol_format(h223_tree, proto_malformed, - tvb, 0, 0, "[Malformed Packet: %s]", - pinfo->current_proto); + show_exception(tvb, pinfo, h223_tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; diff --git a/epan/dissectors/packet-ieee80211.c b/epan/dissectors/packet-ieee80211.c index 33efacc621..1ad4ba0a58 100644 --- a/epan/dissectors/packet-ieee80211.c +++ b/epan/dissectors/packet-ieee80211.c @@ -12985,7 +12985,7 @@ dissect_ieee80211_common (tvbuff_t *tvb, packet_info *pinfo, packet starts with 0x00 0x00 and, if so, treat it as an OLPC frame. */ encap_type = ENCAP_802_2; - TRY { + if (tvb_bytes_exist(next_tvb, 0, 2)) { octet1 = tvb_get_guint8(next_tvb, 0); octet2 = tvb_get_guint8(next_tvb, 1); if ((octet1 != 0xaa) || (octet2 != 0xaa)) { @@ -13000,11 +13000,6 @@ dissect_ieee80211_common (tvbuff_t *tvb, packet_info *pinfo, } } } - CATCH2(BoundsError, ReportedBoundsError) { - ; /* do nothing */ - - } - ENDTRY; switch (encap_type) { diff --git a/epan/dissectors/packet-ieee802154.c b/epan/dissectors/packet-ieee802154.c index a602222ee2..9d8b9a1653 100644 --- a/epan/dissectors/packet-ieee802154.c +++ b/epan/dissectors/packet-ieee802154.c @@ -75,6 +75,7 @@ #include #include #include +#include /* Use libgcrypt for cipher libraries. */ #ifdef HAVE_LIBGCRYPT @@ -82,7 +83,6 @@ #endif /* HAVE_LIBGCRYPT */ #include "packet-ieee802154.h" -#include "packet-frame.h" /* For Exception Handling */ #include "packet-sll.h" /* Dissection Options for dissect_ieee802154_common */ diff --git a/epan/dissectors/packet-ieee8023.c b/epan/dissectors/packet-ieee8023.c index bd9b473ae7..89d1e14b25 100644 --- a/epan/dissectors/packet-ieee8023.c +++ b/epan/dissectors/packet-ieee8023.c @@ -27,9 +27,9 @@ #include #include #include +#include #include "packet-ieee8023.h" #include "packet-eth.h" -#include "packet-frame.h" static dissector_handle_t ipx_handle; static dissector_handle_t llc_handle; @@ -43,7 +43,7 @@ dissect_802_3(volatile int length, gboolean is_802_2, tvbuff_t *tvb, { proto_item *length_it; tvbuff_t *volatile next_tvb = NULL; - tvbuff_t *volatile trailer_tvb = NULL; + tvbuff_t *trailer_tvb = NULL; const char *saved_proto; gint captured_length, reported_length; void *pd_save; @@ -74,20 +74,6 @@ dissect_802_3(volatile int length, gboolean is_802_2, tvbuff_t *tvb, if (captured_length > length) captured_length = length; next_tvb = tvb_new_subset(tvb, offset_after_length, captured_length, length); - TRY { - trailer_tvb = tvb_new_subset_remaining(tvb, offset_after_length + length); - } - CATCH2(BoundsError, ReportedBoundsError) { - /* The packet has exactly "length" bytes worth of captured data - left in it, so the "tvb_new_subset()" creating "trailer_tvb" - threw an exception. - - This means that all the data in the frame is within the length - value (assuming our offset isn't past the end of the tvb), so - we give all the data to the next protocol and have no trailer. */ - trailer_tvb = NULL; - } - ENDTRY; /* Dissect the payload either as IPX or as an LLC frame. Catch BoundsError and ReportedBoundsError, so that if the @@ -109,31 +95,33 @@ dissect_802_3(volatile int length, gboolean is_802_2, tvbuff_t *tvb, call_dissector(ccsds_handle, next_tvb, pinfo, tree); } } - CATCH(BoundsError) { - /* Somebody threw BoundsError, which means that dissecting the payload - found that the packet was cut off by a snapshot length before the - end of the payload. The trailer comes after the payload, so *all* - of the trailer is cut off - don't bother adding the trailer, just - rethrow the exception so it gets reported. */ - RETHROW; - } - CATCH_ALL { - /* Well, somebody threw an exception other than BoundsError. - Show the exception, and then drive on to show the trailer, - restoring the protocol value that was in effect before we - called the subdissector. */ + CATCH_NONFATAL_ERRORS { + /* Somebody threw an exception that means that there was a problem + dissecting the payload; that means that a dissector was found, + so we don't need to dissect the payload as data or update the + protocol or info columns. - /* Restore the private_data structure in case one of the - * called dissectors modified it (and, due to the exception, - * was unable to restore it). - */ + Just show the exception and then drive on to show the trailer, + after noting that a dissector was found and restoring the + protocol value that was in effect before we called the subdissector. */ pinfo->private_data = pd_save; show_exception(next_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); - pinfo->current_proto = saved_proto; } ENDTRY; + /* Restore the protocol value, so that any exception thrown by + tvb_new_subset_remaining() refers to the protocol for which + this is a trailer, and restore the private_data structure in + case one of the called dissectors modified it. */ + pinfo->private_data = pd_save; + pinfo->current_proto = saved_proto; + + /* Construct a tvbuff for the trailer; if the trailer is past the + end of the captured data, this will throw a BoundsError, which + is what we want, as it'll report that the packet was cut short. */ + trailer_tvb = tvb_new_subset_remaining(tvb, offset_after_length + length); + add_ethernet_trailer(pinfo, tree, fh_tree, trailer_id, tvb, trailer_tvb, fcs_len); } diff --git a/epan/dissectors/packet-infiniband.c b/epan/dissectors/packet-infiniband.c index 560f405b53..4409ed5bc4 100644 --- a/epan/dissectors/packet-infiniband.c +++ b/epan/dissectors/packet-infiniband.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include "packet-infiniband.h" #define PROTO_TAG_INFINIBAND "Infiniband" @@ -2520,40 +2520,21 @@ static void parse_PAYLOAD(proto_tree *parentTree, packet_info *pinfo, tvbuff_t * dissector_found = dissector_try_uint(ethertype_dissector_table, etype, next_tvb, pinfo, top_tree); } - CATCH(BoundsError) { - /* Somebody threw BoundsError, which means that: + CATCH_NONFATAL_ERRORS { + /* Somebody threw an exception that means that there + was a problem dissecting the payload; that means + that a dissector was found, so we don't need to + dissect the payload as data or update the protocol + or info columns. - 1) a dissector was found, so we don't need to - dissect the payload as data or update the - protocol or info columns; + Just show the exception and then drive on to show + the trailer, after noting that a dissector was found + and restoring the protocol value that was in effect + before we called the subdissector. - 2) dissecting the payload found that the packet was - cut off by a snapshot length before the end of - the payload. The trailer comes after the payload, - so *all* of the trailer is cut off, and we'll - just get another BoundsError if we add the trailer. - - Therefore, we just rethrow the exception so it gets - reported; we don't dissect the trailer or do anything - else. */ - RETHROW; - } - CATCH(OutOfMemoryError) { - RETHROW; - } - CATCH_ALL { - /* Somebody threw an exception other than BoundsError, which - means that a dissector was found, so we don't need to - dissect the payload as data or update the protocol or info - columns. We just show the exception and then drive on - to show the trailer, after noting that a dissector was - found and restoring the protocol value that was in effect - before we called the subdissector. */ - - /* Restore the private_data structure in case one of the - * called dissectors modified it (and, due to the exception, - * was unable to restore it). - */ + Restore the private_data structure in case one of the + called dissectors modified it (and, due to the exception, + was unable to restore it). */ pinfo->private_data = pd_save; show_exception(next_tvb, pinfo, top_tree, EXCEPT_CODE, GET_MESSAGE); diff --git a/epan/dissectors/packet-isl.c b/epan/dissectors/packet-isl.c index b58ca4c414..cac933a370 100644 --- a/epan/dissectors/packet-isl.c +++ b/epan/dissectors/packet-isl.c @@ -26,11 +26,12 @@ #include #include +#include +#include + #include "packet-isl.h" #include "packet-eth.h" #include "packet-tr.h" -#include "packet-frame.h" -#include /* * See @@ -194,7 +195,7 @@ dissect_isl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int fcs_len) payload_tvb = tvb_new_subset(tvb, 14, length, length); trailer_tvb = tvb_new_subset_remaining(tvb, 14 + length); } - CATCH2(BoundsError, ReportedBoundsError) { + CATCH_BOUNDS_ERRORS { /* Either: the packet doesn't have "length" bytes worth of @@ -206,7 +207,7 @@ dissect_isl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int fcs_len) or the packet has exactly "length" bytes worth of - captured data left in it, so the "tvb_new_subset()" + captured data left in it, so the "tvb_new_subset_remaining()" creating "trailer_tvb" threw an exception. In either case, this means that all the data in the frame @@ -275,24 +276,18 @@ dissect_isl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int fcs_len) /* Frames encapsulated in ISL include an FCS. */ call_dissector(eth_withfcs_handle, next_tvb, pinfo, tree); } - CATCH(BoundsError) { - /* Somebody threw BoundsError, which means that dissecting the payload - found that the packet was cut off by a snapshot length before the - end of the payload. The trailer comes after the payload, so *all* - of the trailer is cut off - don't bother adding the trailer, just - rethrow the exception so it gets reported. */ - RETHROW; - } - CATCH_ALL { - /* Well, somebody threw an exception other than BoundsError. + CATCH_NONFATAL_ERRORS { + /* Somebody threw an exception that indicates a problem with + the payload, but doesn't indicate anything that would + keep us from dissecting the trailer. + Show the exception, and then drive on to show the trailer, restoring the protocol value that was in effect before we - called the subdissector. */ + called the subdissector. - /* Restore the private_data structure in case one of the - * called dissectors modified it (and, due to the exception, - * was unable to restore it). - */ + Restore the private_data structure in case one of the + called dissectors modified it (and, due to the exception, + was unable to restore it). */ pinfo->private_data = pd_save; show_exception(next_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); diff --git a/epan/dissectors/packet-kerberos.c b/epan/dissectors/packet-kerberos.c index cfa275fd79..f7cf661f27 100644 --- a/epan/dissectors/packet-kerberos.c +++ b/epan/dissectors/packet-kerberos.c @@ -906,7 +906,7 @@ decrypt_krb5_data(proto_tree *tree, packet_info *pinfo, id_offset = get_ber_identifier(encr_tvb, CONFOUNDER_PLUS_CHECKSUM, &cls, &pc, &tag); offset = get_ber_length(encr_tvb, id_offset, &item_len, &ind); } - CATCH (BoundsError) { + CATCH_BOUNDS_ERRORS { tvb_free(encr_tvb); do_continue = TRUE; } @@ -4777,7 +4777,7 @@ dissect_kerberos_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, TRY { offset=dissect_ber_old_choice(&asn1_ctx, kerberos_tree, tvb, offset, kerberos_applications_choice, -1, -1, NULL); - } CATCH_ALL { + } CATCH_BOUNDS_ERRORS { pinfo->private_data=saved_private_data; RETHROW; } ENDTRY; diff --git a/epan/dissectors/packet-ldap.c b/epan/dissectors/packet-ldap.c index cc74c633ab..0692da7f05 100644 --- a/epan/dissectors/packet-ldap.c +++ b/epan/dissectors/packet-ldap.c @@ -104,7 +104,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/epan/dissectors/packet-ldp.c b/epan/dissectors/packet-ldp.c index 7fc8f2e239..72d283d184 100644 --- a/epan/dissectors/packet-ldp.c +++ b/epan/dissectors/packet-ldp.c @@ -45,8 +45,8 @@ #include #include #include +#include -#include "packet-frame.h" #include "packet-diffserv-mpls-common.h" #include "packet-ldp.h" @@ -3046,30 +3046,26 @@ dissect_ldp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data /* * Dissect the LDP packet. * - * Catch the ReportedBoundsError exception; if this - * particular message happens to get a ReportedBoundsError - * exception, that doesn't mean that we should stop - * dissecting LDP messages within this frame or chunk of - * reassembled data. + * If it gets an error that means there's no point in + * dissecting any more PDUs, rethrow the exception in + * question. * - * If it gets a BoundsError, we can stop, as there's nothing - * more to see, so we just re-throw it. + * If it gets any other error, report it and continue, as that + * means that PDU got an error, but that doesn't mean we should + * stop dissecting PDUs within this frame or chunk of reassembled + * data. */ pd_save = pinfo->private_data; TRY { dissect_ldp_pdu(next_tvb, pinfo, tree); } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { + CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; diff --git a/epan/dissectors/packet-lmp.c b/epan/dissectors/packet-lmp.c index e73cbb9639..5e811dc904 100644 --- a/epan/dissectors/packet-lmp.c +++ b/epan/dissectors/packet-lmp.c @@ -49,14 +49,14 @@ #include #include -#include +#include #include #include #include +#include #include "packet-ip.h" #include "packet-rsvp.h" -#include "packet-frame.h" static int proto_lmp = -1; diff --git a/epan/dissectors/packet-nbns.c b/epan/dissectors/packet-nbns.c index b9894fb136..8953a24c36 100644 --- a/epan/dissectors/packet-nbns.c +++ b/epan/dissectors/packet-nbns.c @@ -31,12 +31,13 @@ #include #include +#include +#include +#include + #include "packet-dns.h" #include "packet-netbios.h" #include "packet-tcp.h" -#include "packet-frame.h" -#include -#include static int proto_nbns = -1; static int hf_nbns_flags = -1; @@ -1605,30 +1606,29 @@ dissect_nbss_packet(tvbuff_t *tvb, int offset, packet_info *pinfo, next_tvb = tvb_new_subset(tvb, offset, len, reported_len); /* - * Catch the ReportedBoundsError exception; if this - * particular message happens to get a ReportedBoundsError - * exception, that doesn't mean that we should stop - * dissecting NetBIOS messages within this frame or chunk - * of reassembled data. + * Dissect the message. * - * If it gets a BoundsError, we can stop, as there's nothing - * more to see, so we just re-throw it. + * If it gets an error that means there's no point in + * dissecting any more PDUs, rethrow the exception in + * question. + * + * If it gets any other error, report it and continue, as that + * means that PDU got an error, but that doesn't mean we should + * stop dissecting PDUs within this frame or chunk of reassembled + * data. */ saved_proto = pinfo->current_proto; pd_save = pinfo->private_data; TRY { dissect_netbios_payload(next_tvb, pinfo, tree); } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { + CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); pinfo->current_proto = saved_proto; } ENDTRY; diff --git a/epan/dissectors/packet-negoex.c b/epan/dissectors/packet-negoex.c index 31d8aa8d4f..5ca3c6471c 100644 --- a/epan/dissectors/packet-negoex.c +++ b/epan/dissectors/packet-negoex.c @@ -29,8 +29,8 @@ #include #include +#include -#include "packet-frame.h" #include "packet-dcerpc.h" #include "packet-gssapi.h" @@ -504,11 +504,9 @@ dissect_negoex(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) bad_message: ; - } CATCH(BoundsError) { - RETHROW; - } CATCH(ReportedBoundsError) { + } CATCH_NONFATAL_ERRORS { done = TRUE; - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; } diff --git a/epan/dissectors/packet-ntlmssp.c b/epan/dissectors/packet-ntlmssp.c index 7bd85d6bb3..180d0554e3 100644 --- a/epan/dissectors/packet-ntlmssp.c +++ b/epan/dissectors/packet-ntlmssp.c @@ -35,20 +35,20 @@ #include #include - -#include "packet-windows-common.h" -#include "packet-smb-common.h" -#include "packet-frame.h" #include -#include "packet-kerberos.h" #include #include #include #include +#include #include #include #include #include + +#include "packet-windows-common.h" +#include "packet-smb-common.h" +#include "packet-kerberos.h" #include "packet-dcerpc.h" #include "packet-gssapi.h" #include @@ -1989,15 +1989,13 @@ dissect_ntlmssp_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi /* let's try to hook ourselves here */ offset += 12; - } CATCH(BoundsError) { - RETHROW; - } CATCH(ReportedBoundsError) { + } CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; return offset; @@ -2189,15 +2187,13 @@ dissect_ntlmssp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) "Unrecognized NTLMSSP Message"); break; } - } CATCH(BoundsError) { - RETHROW; - } CATCH(ReportedBoundsError) { + } CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; tap_queue_packet(ntlmssp_tap, pinfo, ntlmssph); @@ -2432,15 +2428,13 @@ dissect_ntlmssp_payload_only(tvbuff_t *tvb, packet_info *pinfo, _U_ proto_tree * decrypt_data_payload (tvb, offset, encrypted_block_length, pinfo, ntlmssp_tree, NULL); /* let's try to hook ourselves here */ - } CATCH(BoundsError) { - RETHROW; - } CATCH(ReportedBoundsError) { + } CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; return offset; @@ -2507,15 +2501,13 @@ dissect_ntlmssp_verf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void * offset += 12; offset += encrypted_block_length; - } CATCH(BoundsError) { - RETHROW; - } CATCH(ReportedBoundsError) { + } CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; return offset; diff --git a/epan/dissectors/packet-pcep.c b/epan/dissectors/packet-pcep.c index ce61f55790..1342464ccb 100644 --- a/epan/dissectors/packet-pcep.c +++ b/epan/dissectors/packet-pcep.c @@ -36,8 +36,6 @@ #include #include -#include "packet-frame.h" - /*differents types of objects*/ #define PCEP_OPEN_OBJ 1 #define PCEP_RP_OBJ 2 @@ -2614,10 +2612,6 @@ dissect_pcep_msg_tree(tvbuff_t *tvb, proto_tree *tree, guint tree_mode, packet_i hidden_item = proto_tree_add_boolean(pcep_header_tree, pcep_filter[PCEPF_MSG + message_type], tvb, offset+1, 1, 1); PROTO_ITEM_SET_HIDDEN(hidden_item); break; - - default: - proto_tree_add_protocol_format(pcep_header_tree, proto_malformed, tvb, offset+1, 1, "Invalid message type: %u", message_type); - return; } offset = 4; diff --git a/epan/dissectors/packet-rpc.c b/epan/dissectors/packet-rpc.c index ae67b68c2d..61ceacd1db 100644 --- a/epan/dissectors/packet-rpc.c +++ b/epan/dissectors/packet-rpc.c @@ -34,17 +34,18 @@ #include #include #include -#include "packet-rpc.h" -#include "packet-frame.h" -#include "packet-tcp.h" #include #include -#include -#include "packet-nfs.h" #include #include #include #include +#include + +#include "packet-rpc.h" +#include "packet-tcp.h" +#include +#include "packet-nfs.h" /* * See: @@ -3062,17 +3063,6 @@ call_message_dissector(tvbuff_t *tvb, tvbuff_t *rec_tvb, packet_info *pinfo, volatile gboolean rpc_succeeded; void *pd_save; - /* - * Catch the ReportedBoundsError exception; if - * this particular message happens to get a - * ReportedBoundsError exception, that doesn't - * mean that we should stop dissecting RPC - * messages within this frame or chunk of - * reassembled data. - * - * If it gets a BoundsError, we can stop, as there's - * nothing more to see, so we just re-throw it. - */ saved_proto = pinfo->current_proto; rpc_succeeded = FALSE; pd_save = pinfo->private_data; @@ -3080,11 +3070,17 @@ call_message_dissector(tvbuff_t *tvb, tvbuff_t *rec_tvb, packet_info *pinfo, rpc_succeeded = (*dissector)(rec_tvb, pinfo, tree, frag_tvb, ipfd_head, TRUE, rpc_rm, first_pdu); } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { - show_reported_bounds_error(tvb, pinfo, tree); + CATCH_NONFATAL_ERRORS { + /* + * Somebody threw an exception that means that there + * was a problem dissecting the payload; that means + * that a dissector was found, so we don't need to + * dissect the payload as data or update the protocol + * or info columns. + * + * Just show the exception and then continue dissecting. + */ + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); pinfo->current_proto = saved_proto; /* Restore the private_data structure in case one of the diff --git a/epan/dissectors/packet-rsvp.c b/epan/dissectors/packet-rsvp.c index 00b36951ce..0c27c1c638 100644 --- a/epan/dissectors/packet-rsvp.c +++ b/epan/dissectors/packet-rsvp.c @@ -111,7 +111,6 @@ #include "packet-rsvp.h" #include "packet-ip.h" -#include "packet-frame.h" #include "packet-diffserv-mpls-common.h" #include "packet-osi.h" @@ -6292,11 +6291,6 @@ dissect_rsvp_msg_tree(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, offset+1, 1, 1); PROTO_ITEM_SET_HIDDEN(hidden_item); break; - - default: - proto_tree_add_protocol_format(rsvp_header_tree, proto_malformed, tvb, offset+1, 1, - "Invalid message type: %u", message_type); - return; } cksum = tvb_get_ntohs(tvb, offset+2); diff --git a/epan/dissectors/packet-scsi.h b/epan/dissectors/packet-scsi.h index 509f4f574d..7a3e3b5c09 100644 --- a/epan/dissectors/packet-scsi.h +++ b/epan/dissectors/packet-scsi.h @@ -290,9 +290,6 @@ extern value_string_ext scsi_asc_val_ext; THROW(ScsiBoundsError); \ } \ } \ - CATCH_ALL { \ - RETHROW; \ - } \ ENDTRY; \ } diff --git a/epan/dissectors/packet-sctp.c b/epan/dissectors/packet-sctp.c index c2b1c669a9..ec47ffd7e5 100644 --- a/epan/dissectors/packet-sctp.c +++ b/epan/dissectors/packet-sctp.c @@ -59,14 +59,15 @@ #include #include #include -#include "packet-sctp.h" #include #include #include -#include +#include #include #include +#include "packet-sctp.h" + #define LT(x, y) ((gint32)((x) - (y)) < 0) #define ADD_PADDING(x) ((((x) + 3) >> 2) << 2) @@ -2866,28 +2867,25 @@ dissect_data_chunk(tvbuff_t *chunk_tvb, void *pd_save; volatile gboolean retval = FALSE; - /* - * If this chunk (which might be a fragment) happens to get a - * ReportedBoundsError exception, don't stop dissecting chunks within this - * frame. - * - * If it gets a BoundsError, we can stop, as there's nothing more to - * see, so we just re-throw it. - */ pd_save = pinfo->private_data; TRY { retval = dissect_payload(payload_tvb, pinfo, tree, payload_proto_id); } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { - /* Restore the private_data structure in case one of the - * called dissectors modified it (and, due to the exception, - * was unable to restore it). + CATCH_NONFATAL_ERRORS { + /* + * Somebody threw an exception that means that there was a problem + * dissecting the payload; that means that a dissector was found, + * so we don't need to dissect the payload as data or update the + * protocol or info columns. + * + * Just show the exception and then continue dissecting chunks. + * + * Restore the private_data structure in case one of the + * called dissectors modified it (and, due to the exception, + * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(payload_tvb, pinfo, tree); + show_exception(payload_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; diff --git a/epan/dissectors/packet-sdp.c b/epan/dissectors/packet-sdp.c index 3046faf8c5..0bdcddbb13 100644 --- a/epan/dissectors/packet-sdp.c +++ b/epan/dissectors/packet-sdp.c @@ -59,11 +59,11 @@ #include #include #include +#include +#include #include "packet-sdp.h" -#include "packet-frame.h" #include "packet-rtp.h" -#include #include "packet-rtcp.h" #include "packet-t38.h" @@ -1063,11 +1063,8 @@ decode_sdp_fmtp(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint offset TRY { dissect_h264_nal_unit(data_tvb, pinfo, tree); } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { - show_reported_bounds_error(tvb, pinfo, tree); + CATCH_NONFATAL_ERRORS { + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; if (comma_offset != -1) { diff --git a/epan/dissectors/packet-ses.c b/epan/dissectors/packet-ses.c index ea646593d9..be59773171 100644 --- a/epan/dissectors/packet-ses.c +++ b/epan/dissectors/packet-ses.c @@ -34,10 +34,10 @@ #include #include #include +#include #include "packet-ber.h" #include "packet-ses.h" -#include "packet-frame.h" /* #include */ #include diff --git a/epan/dissectors/packet-sflow.c b/epan/dissectors/packet-sflow.c index dcc9247b05..6145543623 100644 --- a/epan/dissectors/packet-sflow.c +++ b/epan/dissectors/packet-sflow.c @@ -839,7 +839,7 @@ dissect_sflow_245_sampled_header(tvbuff_t *tvb, packet_info *pinfo, } } - CATCH2(BoundsError, ReportedBoundsError) { + CATCH_BOUNDS_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). diff --git a/epan/dissectors/packet-t124.c b/epan/dissectors/packet-t124.c index cd2d5de914..5df10a6f63 100644 --- a/epan/dissectors/packet-t124.c +++ b/epan/dissectors/packet-t124.c @@ -2973,7 +2973,7 @@ dissect_t124_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, vo */ TRY { (void) dissect_per_sequence(tvb, 0, &asn1_ctx, NULL, -1, -1, t124Heur_sequence); - } CATCH2(BoundsError, ReportedBoundsError) { + } CATCH_BOUNDS_ERRORS { failed = TRUE; } ENDTRY; diff --git a/epan/dissectors/packet-t125.c b/epan/dissectors/packet-t125.c index 89f5b0fbf4..301a9ae0d1 100644 --- a/epan/dissectors/packet-t125.c +++ b/epan/dissectors/packet-t125.c @@ -437,7 +437,7 @@ dissect_t125_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, vo TRY { /* could be BER */ get_ber_identifier(tvb, 0, &ber_class, &pc, &tag); - } CATCH2(BoundsError, ReportedBoundsError) { + } CATCH_BOUNDS_ERRORS { failed = TRUE; } ENDTRY; @@ -454,7 +454,7 @@ dissect_t125_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, vo dissect_per_constrained_integer(tvb, 0, &asn1_ctx, NULL, hf_t125_heur, 0, 42, &choice_index, FALSE); - } CATCH2(BoundsError, ReportedBoundsError) { + } CATCH_BOUNDS_ERRORS { failed = TRUE; } ENDTRY; diff --git a/epan/dissectors/packet-tcap.c b/epan/dissectors/packet-tcap.c index c9bab2116c..f4b75c1a70 100644 --- a/epan/dissectors/packet-tcap.c +++ b/epan/dissectors/packet-tcap.c @@ -41,11 +41,11 @@ #include #include #include +#include #include #include "packet-ber.h" #include "packet-tcap.h" -#include "packet-frame.h" #include #define PNAME "Transaction Capabilities Application Part" @@ -673,11 +673,8 @@ TRY { NULL); } -CATCH(BoundsError) { - RETHROW; -} -CATCH(ReportedBoundsError) { - show_reported_bounds_error(tvb, actx->pinfo, tree); +CATCH_NONFATAL_ERRORS { + show_exception(tvb, actx->pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; @@ -742,7 +739,7 @@ dissect_tcap_OCTET_STRING_SIZE_1_4(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, static int dissect_tcap_OrigTransactionID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { -#line 126 "../../asn1/tcap/tcap.cnf" +#line 123 "../../asn1/tcap/tcap.cnf" tvbuff_t *parameter_tvb; guint8 len, i; proto_item *tid_item; @@ -797,7 +794,7 @@ static const ber_sequence_t Begin_sequence[] = { static int dissect_tcap_Begin(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { -#line 204 "../../asn1/tcap/tcap.cnf" +#line 201 "../../asn1/tcap/tcap.cnf" gp_tcapsrt_info->ope=TC_BEGIN; /* Do not change col_add_str() to col_append_str() here: we _want_ this call @@ -819,7 +816,7 @@ gp_tcapsrt_info->ope=TC_BEGIN; static int dissect_tcap_DestTransactionID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { -#line 167 "../../asn1/tcap/tcap.cnf" +#line 164 "../../asn1/tcap/tcap.cnf" tvbuff_t *parameter_tvb; guint8 len , i; proto_item *tid_item; @@ -871,7 +868,7 @@ static const ber_sequence_t End_sequence[] = { static int dissect_tcap_End(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { -#line 218 "../../asn1/tcap/tcap.cnf" +#line 215 "../../asn1/tcap/tcap.cnf" gp_tcapsrt_info->ope=TC_END; col_set_str(actx->pinfo->cinfo, COL_INFO, "End "); @@ -893,7 +890,7 @@ static const ber_sequence_t Continue_sequence[] = { static int dissect_tcap_Continue(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { -#line 225 "../../asn1/tcap/tcap.cnf" +#line 222 "../../asn1/tcap/tcap.cnf" gp_tcapsrt_info->ope=TC_CONT; col_set_str(actx->pinfo->cinfo, COL_INFO, "Continue "); @@ -964,7 +961,7 @@ static const ber_sequence_t Abort_sequence[] = { static int dissect_tcap_Abort(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { -#line 232 "../../asn1/tcap/tcap.cnf" +#line 229 "../../asn1/tcap/tcap.cnf" gp_tcapsrt_info->ope=TC_ABORT; col_set_str(actx->pinfo->cinfo, COL_INFO, "Abort "); @@ -1044,7 +1041,7 @@ dissect_tcap_AUDT_protocol_version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, static int dissect_tcap_AUDT_application_context_name(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { -#line 111 "../../asn1/tcap/tcap.cnf" +#line 108 "../../asn1/tcap/tcap.cnf" offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &cur_oid); tcap_private.oid= (void*) cur_oid; @@ -1141,7 +1138,7 @@ dissect_tcap_AARQ_protocol_version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, static int dissect_tcap_AARQ_application_context_name(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { -#line 116 "../../asn1/tcap/tcap.cnf" +#line 113 "../../asn1/tcap/tcap.cnf" offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &cur_oid); tcap_private.oid= (void*) cur_oid; @@ -1209,7 +1206,7 @@ dissect_tcap_AARE_protocol_version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, static int dissect_tcap_AARE_application_context_name(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) { -#line 121 "../../asn1/tcap/tcap.cnf" +#line 118 "../../asn1/tcap/tcap.cnf" offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &cur_oid); tcap_private.oid= (void*) cur_oid; diff --git a/epan/dissectors/packet-tcp.c b/epan/dissectors/packet-tcp.c index a455492255..206e1a762c 100644 --- a/epan/dissectors/packet-tcp.c +++ b/epan/dissectors/packet-tcp.c @@ -36,14 +36,15 @@ #include #include #include -#include "packet-tcp.h" -#include "packet-frame.h" +#include #include #include #include #include #include +#include "packet-tcp.h" + static int tcp_tap = -1; /* Place TCP summary in proto tree */ @@ -2299,15 +2300,6 @@ tcp_dissect_pdus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, /* * Construct a tvbuff containing the amount of the payload we have * available. Make its reported length the amount of data in the PDU. - * - * XXX - if reassembly isn't enabled. the subdissector will throw a - * BoundsError exception, rather than a ReportedBoundsError exception. - * We really want a tvbuff where the length is "length", the reported - * length is "plen", and the "if the snapshot length were infinite" - * length is the minimum of the reported length of the tvbuff handed - * to us and "plen", with a new type of exception thrown if the offset - * is within the reported length but beyond that third length, with - * that exception getting the "Unreassembled Packet" error. */ length = length_remaining; if (length > plen) @@ -2317,28 +2309,26 @@ tcp_dissect_pdus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, /* * Dissect the PDU. * - * Catch the ReportedBoundsError exception; if this particular message - * happens to get a ReportedBoundsError exception, that doesn't mean - * that we should stop dissecting PDUs within this frame or chunk of - * reassembled data. + * If it gets an error that means there's no point in + * dissecting any more PDUs, rethrow the exception in + * question. * - * If it gets a BoundsError, we can stop, as there's nothing more to - * see, so we just re-throw it. + * If it gets any other error, report it and continue, as that + * means that PDU got an error, but that doesn't mean we should + * stop dissecting PDUs within this frame or chunk of reassembled + * data. */ pd_save = pinfo->private_data; TRY { (*dissect_pdu)(next_tvb, pinfo, tree); } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { + CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; diff --git a/epan/dissectors/packet-tds.c b/epan/dissectors/packet-tds.c index e272baaa5b..f761c31dbf 100644 --- a/epan/dissectors/packet-tds.c +++ b/epan/dissectors/packet-tds.c @@ -156,8 +156,7 @@ #include #include #include - -#include "packet-frame.h" +#include #include #include #include @@ -2578,30 +2577,27 @@ dissect_tds_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* * Dissect the Netlib buffer. * - * Catch the ReportedBoundsError exception; if this - * particular Netlib buffer happens to get a - * ReportedBoundsError exception, that doesn't mean - * that we should stop dissecting PDUs within this frame - * or chunk of reassembled data. + * If it gets an error that means there's no point in + * dissecting any more Netlib buffers, rethrow the + * exception in question. * - * If it gets a BoundsError, we can stop, as there's nothing - * more to see, so we just re-throw it. + * If it gets any other error, report it and continue, as that + * means that Netlib buffer got an error, but that doesn't mean + * we should stop dissecting Netlib buffers within this frame + * or chunk of reassembled data. */ pd_save = pinfo->private_data; TRY { dissect_netlib_buffer(next_tvb, pinfo, tree); } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { + CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; diff --git a/epan/dissectors/packet-tpkt.c b/epan/dissectors/packet-tpkt.c index c9b9bc27a7..b9dd8866be 100644 --- a/epan/dissectors/packet-tpkt.c +++ b/epan/dissectors/packet-tpkt.c @@ -30,13 +30,16 @@ #include "config.h" +#include + #include + #include +#include +#include #include "packet-tpkt.h" -#include "packet-frame.h" -#include -#include + /* TPKT header fields */ static int proto_tpkt = -1; static protocol_t *proto_tpkt_ptr; @@ -323,31 +326,28 @@ dissect_asciitpkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, /* * Call the subdissector. * - * Catch the ReportedBoundsError exception; if this - * particular message happens to get a ReportedBoundsError - * exception, that doesn't mean that we should stop - * dissecting TPKT messages within this frame or chunk - * of reassembled data. + * If it gets an error that means there's no point in + * dissecting any more TPKT messages, rethrow the + * exception in question. * - * If it gets a BoundsError, we can stop, as there's nothing - * more to see, so we just re-throw it. + * If it gets any other error, report it and continue, as that + * means that TPKT message got an error, but that doesn't mean + * we should stop dissecting TPKT messages within this frame + * or chunk of reassembled data. */ pd_save = pinfo->private_data; TRY { call_dissector(subdissector_handle, next_tvb, pinfo, tree); } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { + CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; @@ -539,31 +539,29 @@ dissect_tpkt_encap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, /* * Call the subdissector. * - * Catch the ReportedBoundsError exception; if this - * particular message happens to get a ReportedBoundsError - * exception, that doesn't mean that we should stop - * dissecting TPKT messages within this frame or chunk - * of reassembled data. + * If it gets an error that means there's no point in + * dissecting any more TPKT messages, rethrow the + * exception in question. * - * If it gets a BoundsError, we can stop, as there's nothing - * more to see, so we just re-throw it. + * If it gets any other error, report it and continue, + * as that means that TPKT message got an error, but + * that doesn't mean we should stop dissecting TPKT + * messages within this frame or chunk of reassembled + * data. */ pd_save = pinfo->private_data; TRY { call_dissector(subdissector_handle, next_tvb, pinfo, tree); } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { + CATCH_NONFATAL_ERRORS { /* Restore the private_data structure in case one of the * called dissectors modified it (and, due to the exception, * was unable to restore it). */ pinfo->private_data = pd_save; - show_reported_bounds_error(tvb, pinfo, tree); + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; diff --git a/epan/dissectors/packet-wassp.c b/epan/dissectors/packet-wassp.c index 1f31474ae7..9cc9f0dad5 100644 --- a/epan/dissectors/packet-wassp.c +++ b/epan/dissectors/packet-wassp.c @@ -48,6 +48,7 @@ #include #include #include +#include /* protocol handles */ static int proto_wassp = -1; @@ -781,13 +782,8 @@ dissect_snmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *wassp_tree, /* Continue after SNMP dissection errors */ TRY { call_dissector(snmp_handle, snmp_tvb, pinfo, wassp_tree); - } CATCH2(BoundsError, ReportedBoundsError) { - expert_add_info_format(pinfo, NULL, - PI_MALFORMED, PI_ERROR, - "Malformed or short SNMP subpacket"); - - col_append_str(pinfo->cinfo, COL_INFO, - " [Malformed or short SNMP subpacket] " ); + } CATCH_NONFATAL_ERRORS { + show_exception(snmp_tvb, pinfo, wassp_tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; if (check_col(pinfo->cinfo, COL_INFO)) @@ -813,13 +809,8 @@ dissect_ieee80211(tvbuff_t *tvb, packet_info *pinfo, proto_tree *wassp_tree, /* Continue after IEEE 802.11 dissection errors */ TRY { call_dissector(ieee80211_handle, ieee80211_tvb, pinfo, wassp_tree); - } CATCH2(BoundsError, ReportedBoundsError) { - expert_add_info_format(pinfo, NULL, - PI_MALFORMED, PI_ERROR, - "Malformed or short IEEE 802.11 subpacket"); - - col_append_str(pinfo->cinfo, COL_INFO, - " [Malformed or short IEEE 802.11 subpacket] " ); + } CATCH_NONFATAL_ERRORS { + show_exception(ieee80211_tvb, pinfo, wassp_tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; if (check_col(pinfo->cinfo, COL_INFO)) diff --git a/epan/dissectors/packet-windows-common.c b/epan/dissectors/packet-windows-common.c index 3f996720fb..ce199a8117 100644 --- a/epan/dissectors/packet-windows-common.c +++ b/epan/dissectors/packet-windows-common.c @@ -2411,6 +2411,11 @@ dissect_nt_acl(tvbuff_t *tvb, int offset, packet_info *pinfo, while(num_aces-- && !missing_data && !bad_ace) { pre_ace_offset = offset; + /* + * These are at an offset later in the packet; don't + * fail if we can't fetch them, just note the problem + * and dissect the stuff before it. + */ TRY { offset = dissect_nt_v2_ace(tvb, offset, pinfo, tree, drep, ami); if (pre_ace_offset == offset) { @@ -2421,8 +2426,13 @@ dissect_nt_acl(tvbuff_t *tvb, int offset, packet_info *pinfo, } } - CATCH2(BoundsError, ReportedBoundsError) { - proto_tree_add_text(tree, tvb, offset, 0, "ACE Extends beyond end of captured or reassembled buffer"); + CATCH(BoundsError) { + proto_tree_add_text(tree, tvb, offset, 0, "ACE Extends beyond end of captured data"); + missing_data = TRUE; + } + + CATCH(ReportedBoundsError) { + proto_tree_add_text(tree, tvb, offset, 0, "ACE Extends beyond end of reassembled data"); missing_data = TRUE; } @@ -2681,8 +2691,12 @@ dissect_nt_sec_desc(tvbuff_t *tvb, int offset, packet_info *pinfo, end_offset = offset; } - CATCH2(BoundsError, ReportedBoundsError) { - proto_tree_add_text(tree, tvb, item_offset, 0, "Owner SID beyond end of captured or reassembled buffer"); + CATCH(BoundsError) { + proto_tree_add_text(tree, tvb, item_offset, 0, "Owner SID beyond end of captured data"); + } + + CATCH(ReportedBoundsError) { + proto_tree_add_text(tree, tvb, item_offset, 0, "Owner SID beyond end of reassembled data"); } ENDTRY; @@ -2703,8 +2717,12 @@ dissect_nt_sec_desc(tvbuff_t *tvb, int offset, packet_info *pinfo, end_offset = offset; } - CATCH2(BoundsError, ReportedBoundsError) { - proto_tree_add_text(tree, tvb, item_offset, 0, "Group SID beyond end of captured or reassembled buffer"); + CATCH(BoundsError) { + proto_tree_add_text(tree, tvb, item_offset, 0, "Group SID beyond end of captured data"); + } + + CATCH(ReportedBoundsError) { + proto_tree_add_text(tree, tvb, item_offset, 0, "Group SID beyond end of reassembled data"); } ENDTRY; diff --git a/epan/dissectors/packet-x11.c b/epan/dissectors/packet-x11.c index 9bebe16bc6..817b09fad7 100644 --- a/epan/dissectors/packet-x11.c +++ b/epan/dissectors/packet-x11.c @@ -1273,11 +1273,8 @@ static const value_string zero_is_none_vals[] = { func(next_tvb, pinfo, tree, sep, state, byte_order); \ } \ \ - CATCH(BoundsError) { \ - RETHROW; \ - } \ - CATCH(ReportedBoundsError) { \ - show_reported_bounds_error(next_tvb, pinfo, tree); \ + CATCH_NONFATAL_ERRORS { \ + show_exception(next_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); \ } \ ENDTRY; \ \ @@ -4536,11 +4533,8 @@ static void dissect_x11_requests(tvbuff_t *tvb, packet_info *pinfo, state, byte_order); } } - CATCH(BoundsError) { - RETHROW; - } - CATCH(ReportedBoundsError) { - show_reported_bounds_error(tvb, pinfo, tree); + CATCH_NONFATAL_ERRORS { + show_exception(tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE); } ENDTRY; diff --git a/epan/exceptions.h b/epan/exceptions.h index 92b91ca29f..87431a9bf0 100644 --- a/epan/exceptions.h +++ b/epan/exceptions.h @@ -95,6 +95,40 @@ **/ #define OutOfMemoryError 6 +/* + * Catch errors that, if you're calling a subdissector and catching + * exceptions from the subdissector, and possibly dissecting more + * stuff after the subdissector returns or fails, mean it makes + * sense to continue dissecting: + * + * BoundsError indicates a configuration problem; there's no point in + * trying to dissect any more data, as there's no more data to dissect. + * + * OutOfMemoryError indicates what its name suggests; there's no point + * in trying to dissect any more data, as you're probably not going to + * have any more memory to use when dissecting them. + * + * Other errors indicate that there's some sort of problem with + * the packet; you should continue dissecting data, as it might + * be OK, and, even if it's not, you should report its problem + * separately. + */ +#define CATCH_NONFATAL_ERRORS \ + CATCH2(ReportedBoundsError, ScsiBoundsError) + +/* + * Catch all bounds-checking errors. + */ +#define CATCH_BOUNDS_ERRORS \ + CATCH3(BoundsError, ReportedBoundsError, ScsiBoundsError) + +/* + * Catch all bounds-checking errors, and catch dissector bugs. + * Should only be used at the top level, so that dissector bugs + * go all the way to the top level and get reported immediately. + */ +#define CATCH_BOUNDS_AND_DISSECTOR_ERRORS \ + CATCH4(BoundsError, ReportedBoundsError, ScsiBoundsError, DissectorError) /* Usage: * @@ -110,6 +144,10 @@ * code; * } * + * CATCH_END_OF_DATA_ERROR { + * code; + * } + * * CATCH_ALL { * code; * } @@ -120,8 +158,8 @@ * * ENDTRY; * - * ********* Never use 'goto' or 'return' inside the TRY, CATCH, CATCH_ALL, - * ********* or FINALLY blocks. Execution must proceed through ENDTRY before + * ********* Never use 'goto' or 'return' inside the TRY, CATCH*, or + * ********* FINALLY blocks. Execution must proceed through ENDTRY before * ********* branching out. * * This is really something like: @@ -183,11 +221,11 @@ * and except_state is used to keep track of where we are. */ #define EXCEPT_CAUGHT 1 /* exception has been caught, no need to rethrow at - * END_TRY */ + * ENDTRY */ #define EXCEPT_RETHROWN 2 /* the exception was rethrown from a CATCH * block. Don't reenter the CATCH blocks, but do - * execute FINALLY and rethrow at END_TRY */ + * execute FINALLY and rethrow at ENDTRY */ #define EXCEPT_FINALLY 4 /* we've entered the FINALLY block - don't allow * RETHROW, and don't reenter FINALLY if a @@ -220,22 +258,40 @@ * it's a one-liner. */ #define CATCH(x) \ - if (except_state == 0 && exc != 0 && exc->except_id.except_code == (x) && \ - (except_state |= EXCEPT_CAUGHT)) \ + if (except_state == 0 && exc != 0 && \ + exc->except_id.except_code == (x) && \ + (except_state |= EXCEPT_CAUGHT)) \ /* user's code goes here */ #define CATCH2(x,y) \ if (except_state == 0 && exc != 0 && \ - (exc->except_id.except_code == (x) || exc->except_id.except_code == (y)) && \ - (except_state|=EXCEPT_CAUGHT)) \ + (exc->except_id.except_code == (x) || \ + exc->except_id.except_code == (y)) && \ + (except_state|=EXCEPT_CAUGHT)) \ + /* user's code goes here */ + +#define CATCH3(x,y,z) \ + if (except_state == 0 && exc != 0 && \ + (exc->except_id.except_code == (x) || \ + exc->except_id.except_code == (y) || \ + exc->except_id.except_code == (z)) && \ + (except_state|=EXCEPT_CAUGHT)) \ + /* user's code goes here */ + +#define CATCH4(w,x,y,z) \ + if (except_state == 0 && exc != 0 && \ + (exc->except_id.except_code == (w) || \ + exc->except_id.except_code == (x) || \ + exc->except_id.except_code == (y) || \ + exc->except_id.except_code == (z)) && \ + (except_state|=EXCEPT_CAUGHT)) \ /* user's code goes here */ #define CATCH_ALL \ if (except_state == 0 && exc != 0 && \ - (except_state|=EXCEPT_CAUGHT)) \ + (except_state|=EXCEPT_CAUGHT)) \ /* user's code goes here */ - #define FINALLY \ if( !(except_state & EXCEPT_FINALLY) && (except_state|=EXCEPT_FINALLY)) \ /* user's code goes here */ diff --git a/epan/packet.c b/epan/packet.c index 1f371463db..e2a2a2fe1c 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -400,9 +400,6 @@ dissect_packet(epan_dissect_t *edt, struct wtap_pkthdr *phdr, g_assert_not_reached(); } } - CATCH(OutOfMemoryError) { - RETHROW; - } ENDTRY; EP_CHECK_CANARY(("after dissecting frame %d",fd->num)); @@ -657,9 +654,6 @@ call_dissector_work_error(dissector_handle_t handle, tvbuff_t *tvb, */ ret = tvb_length(tvb); } - CATCH(OutOfMemoryError) { - RETHROW; - } ENDTRY; col_set_writable(pinfo->cinfo, save_writable); diff --git a/epan/proto.c b/epan/proto.c index 8643a3cda4..f9433f9c17 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -46,6 +46,7 @@ #include "column-utils.h" #include "to_str.h" #include "expert.h" +#include "show_exception.h" #include "wspython/wspy_register.h" @@ -370,6 +371,9 @@ proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_da are merely strings on the GUI tree; they are not filterable */ proto_register_field_array(-1, hf, array_length(hf)); + /* Register the pseudo-protocols used for exceptions. */ + register_show_exception(); + /* Have each built-in dissector register its protocols, fields, dissector tables, and dissectors to be called through a handle, and do whatever one-time initialization it needs to diff --git a/epan/show_exception.c b/epan/show_exception.c new file mode 100644 index 0000000000..68e061eb67 --- /dev/null +++ b/epan/show_exception.c @@ -0,0 +1,146 @@ +/* show_exception.c + * + * Routines to put exception information into the protocol tree + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 2000 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include +#include +#include +#include + +static int proto_short = -1; +int proto_malformed = -1; +static int proto_unreassembled = -1; + +void +register_show_exception(void) +{ + proto_short = proto_register_protocol("Short Frame", "Short frame", "short"); + proto_malformed = proto_register_protocol("Malformed Packet", + "Malformed packet", "malformed"); + proto_unreassembled = proto_register_protocol( + "Unreassembled Fragmented Packet", + "Unreassembled fragmented packet", "unreassembled"); + + /* "Short Frame", "Malformed Packet", and "Unreassembled Fragmented + Packet" aren't really protocols, they're error indications; + disabling them makes no sense. */ + proto_set_cant_toggle(proto_short); + proto_set_cant_toggle(proto_malformed); + proto_set_cant_toggle(proto_unreassembled); +} + +void +show_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, + unsigned long exception, const char *exception_message) +{ + static const char dissector_error_nomsg[] = + "Dissector writer didn't bother saying what the error was"; + proto_item *item; + + + switch (exception) { + + case ScsiBoundsError: + col_append_str(pinfo->cinfo, COL_INFO, "[SCSI transfer limited due to allocation_length too small]"); + /*item =*/ proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0, + "SCSI transfer limited due to allocation_length too small: %s truncated]", pinfo->current_proto); + /* Don't record ScsiBoundsError exceptions as expert events - they merely + * reflect a normal SCSI condition. + * (any case where it's caused by something else is a bug). */ + /* expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Packet size limited");*/ + break; + + case BoundsError: + col_append_str(pinfo->cinfo, COL_INFO, "[Packet size limited during capture]"); + /*item =*/ proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0, + "[Packet size limited during capture: %s truncated]", pinfo->current_proto); + /* Don't record BoundsError exceptions as expert events - they merely + * reflect a capture done with a snapshot length too short to capture + * all of the packet + * (any case where it's caused by something else is a bug). */ + /* expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Packet size limited");*/ + break; + + case ReportedBoundsError: + show_reported_bounds_error(tvb, pinfo, tree); + break; + + case DissectorError: + col_append_fstr(pinfo->cinfo, COL_INFO, + "[Dissector bug, protocol %s: %s]", + pinfo->current_proto, + exception_message == NULL ? + dissector_error_nomsg : exception_message); + item = proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0, + "[Dissector bug, protocol %s: %s]", + pinfo->current_proto, + exception_message == NULL ? + dissector_error_nomsg : exception_message); + g_warning("Dissector bug, protocol %s, in packet %u: %s", + pinfo->current_proto, pinfo->fd->num, + exception_message == NULL ? + dissector_error_nomsg : exception_message); + expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, + "%s", + exception_message == NULL ? + dissector_error_nomsg : exception_message); + break; + + default: + /* XXX - we want to know, if an unknown exception passed until here, don't we? */ + g_assert_not_reached(); + } +} + +void +show_reported_bounds_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + proto_item *item; + + if (pinfo->fragmented) { + /* + * We were dissecting an unreassembled fragmented + * packet when the exception was thrown, so the + * problem isn't that the dissector expected + * something but it wasn't in the packet, the + * problem is that the dissector expected something + * but it wasn't in the fragment we dissected. + */ + col_append_fstr(pinfo->cinfo, COL_INFO, + "[Unreassembled Packet%s] ", + pinfo->noreassembly_reason); + item = proto_tree_add_protocol_format(tree, proto_unreassembled, + tvb, 0, 0, "[Unreassembled Packet%s: %s]", + pinfo->noreassembly_reason, pinfo->current_proto); + expert_add_info_format(pinfo, item, PI_REASSEMBLE, PI_WARN, "Unreassembled Packet (Exception occurred)"); + } else { + col_append_str(pinfo->cinfo, COL_INFO, + "[Malformed Packet]"); + item = proto_tree_add_protocol_format(tree, proto_malformed, + tvb, 0, 0, "[Malformed Packet: %s]", pinfo->current_proto); + expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR, "Malformed Packet (Exception occurred)"); + } +} diff --git a/epan/show_exception.h b/epan/show_exception.h new file mode 100644 index 0000000000..977387235d --- /dev/null +++ b/epan/show_exception.h @@ -0,0 +1,48 @@ +/* show_exception.h + * + * Routines to put exception information into the protocol tree + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 2000 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* + * "Protocol" used for "malformed frame" errors (other than + * ReportedBoundsError exceptions). + */ +extern int proto_malformed; + +/* + * Called to register the pseudo-protocols used for exceptions. + */ +void register_show_exception(void); + +/* + * Routine used to add an indication of an arbitrary exception to the tree. + */ +void show_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, + unsigned long exception, const char *exception_message); + +/* + * Routine used to add an indication of a ReportedBoundsError exception + * to the tree. + */ +void +show_reported_bounds_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree); diff --git a/epan/wslua/init_wslua.c b/epan/wslua/init_wslua.c index 37736340be..3c5c58ed26 100644 --- a/epan/wslua/init_wslua.c +++ b/epan/wslua/init_wslua.c @@ -43,7 +43,6 @@ static lua_State* L = NULL; packet_info* lua_pinfo; struct _wslua_treeitem* lua_tree; tvbuff_t* lua_tvb; -int lua_malformed; int lua_dissectors_table_ref; dissector_handle_t lua_data_handle; @@ -435,7 +434,6 @@ int wslua_init(register_cb cb, gpointer client_data) { lua_tvb = NULL; lua_data_handle = find_dissector("data"); - lua_malformed = proto_get_id_by_filter_name("malformed"); Proto_commit(L); diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index ece978f6bb..696bc2dc75 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -417,7 +417,6 @@ extern C shift##C(lua_State* L,int i) extern packet_info* lua_pinfo; extern TreeItem lua_tree; extern tvbuff_t* lua_tvb; -extern int lua_malformed; extern dissector_handle_t lua_data_handle; extern gboolean lua_initialized; extern int lua_dissectors_table_ref; diff --git a/epan/wslua/wslua_proto.c b/epan/wslua/wslua_proto.c index c53e4aac0a..332ef16ee2 100644 --- a/epan/wslua/wslua_proto.c +++ b/epan/wslua/wslua_proto.c @@ -33,6 +33,8 @@ #include "wslua.h" +#include + WSLUA_CLASS_DEFINE(Pref,NOP,NOP); /* A preference of a Protocol. */ static range_t* get_range(lua_State *L, int idx_r, int idx_m) @@ -1570,8 +1572,8 @@ WSLUA_METHOD Dissector_call(lua_State* L) { TRY { call_dissector(d, tvb->ws_tvb, pinfo->ws_pinfo, ti->tree); /* XXX Are we sure about this??? is this the right/only thing to catch */ - } CATCH(ReportedBoundsError) { - proto_tree_add_protocol_format(lua_tree->tree, lua_malformed, lua_tvb, 0, 0, "[Malformed Frame: Packet Length]" ); + } CATCH_NONFATAL_ERRORS { + show_exception(tvb->ws_tvb, pinfo->ws_pinfo, ti->tree, EXCEPT_CODE, GET_MESSAGE); error = "Malformed frame"; } ENDTRY; @@ -1800,8 +1802,8 @@ WSLUA_METHOD DissectorTable_try (lua_State *L) { call_dissector(lua_data_handle,tvb->ws_tvb,pinfo->ws_pinfo,ti->tree); /* XXX Are we sure about this??? is this the right/only thing to catch */ - } CATCH(ReportedBoundsError) { - proto_tree_add_protocol_format(lua_tree->tree, lua_malformed, lua_tvb, 0, 0, "[Malformed Frame: Packet Length]" ); + } CATCH_NONFATAL_ERRORS { + show_exception(tvb->ws_tvb, pinfo->ws_pinfo, ti->tree, EXCEPT_CODE, GET_MESSAGE); error = "Malformed frame"; } ENDTRY; diff --git a/plugins/asn1/packet-asn1.c b/plugins/asn1/packet-asn1.c index 82bd349b2d..e3877ddbfe 100644 --- a/plugins/asn1/packet-asn1.c +++ b/plugins/asn1/packet-asn1.c @@ -1007,9 +1007,6 @@ dissect_asn1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { if (ti) proto_item_append_text(ti, ", %d msg%s", i, (i>1)?"s":empty); } - CATCH(BoundsError) { - RETHROW; - } CATCH(ReportedBoundsError) { col_append_fstr(pinfo->cinfo, COL_INFO, "[%d+1 msg%s]", i, (i>0)?"s":empty); if (ti)