Move show_exception() and show_reported_bounds_error() to

epan/show_exception.c, as it's used outside
epan/dissectors/packet-frame.c.  Update their callers to include
<epan/show_exception.h> to get their declaration.

Add a CATCH_NONFATAL_ERRORS macro that catches all exceptions that, if
there's more stuff in the packet to dissect after the dissector call
that threw the exception, doesn't mean you shouldn't go ahead and
dissect that stuff.  Use it in all those cases, including ones where
BoundsError was inappropriately being caught (you want those passed up
to the top level, so that the packet is reported as having been cut
short in the capture process).

Add a CATCH_BOUNDS_ERRORS macro that catches all exceptions that
correspond to running past the end of the data for a tvbuff; use it
rather than explicitly catching those exceptions individually, and
rather than just catching all exceptions (the only place that
DissectorError should be caught, for example, is at the top level, so
dissector bugs show up in the protocol tree).

Don't catch and then immediately rethrow exceptions without doing
anything else; just let the exceptions go up to the final catcher.

Use show_exception() to report non-fatal errors, rather than doing it
yourself.
 
If a dissector is called from Lua, catch all non-fatal errors and use
show_exception() to report them rather than catching only
ReportedBoundsError and adding a proto_malformed item.

Don't catch exceptions when constructing a trailer tvbuff in
packet-ieee8023.c - just construct it after the payload has been
dissected, and let whatever exceptions that throws be handled at the top
level.

Avoid some TRY/CATCH/ENDTRY cases by using checks such as
tvb_bytes_exist() before even looking in the tvbuff.

svn path=/trunk/; revision=47924
This commit is contained in:
Guy Harris 2013-02-27 22:43:54 +00:00
parent 97a0ad8eab
commit 6b629c4d92
55 changed files with 609 additions and 601 deletions

View File

@ -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;

View File

@ -96,7 +96,7 @@
#include <epan/emem.h>
#include <epan/oids.h>
#include <epan/strutil.h>
#include <epan/dissectors/packet-frame.h>
#include <epan/show_exception.h>
#include <epan/dissectors/packet-tcp.h>
#include <epan/dissectors/packet-windows-common.h>
#include <epan/dissectors/packet-dcerpc.h>

View File

@ -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;

View File

@ -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;

View File

@ -33,11 +33,11 @@
#include <epan/oids.h>
#include <epan/asn1.h>
#include <epan/strutil.h>
#include <epan/show_exception.h>
#include <string.h>
#include "packet-ber.h"
#include "packet-tcap.h"
#include "packet-frame.h"
#include <epan/tcap-persistentdata.h>
#define PNAME "Transaction Capabilities Application Part"

View File

@ -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;

View File

@ -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

View File

@ -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 \

View File

@ -59,7 +59,7 @@
#include <epan/packet.h>
#include <epan/addr_and_mask.h>
#include "packet-frame.h"
#include <epan/show_exception.h>
#include <epan/afn.h>
#include <epan/prefs.h>
#include <epan/emem.h>
@ -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;

View File

@ -52,6 +52,7 @@
#include <epan/etypes.h>
#include <epan/expert.h>
#include <epan/prefs.h>
#include <epan/show_exception.h>
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? */

View File

@ -45,7 +45,7 @@
#include <epan/expert.h>
#include <epan/strutil.h>
#include <epan/addr_resolv.h>
#include <epan/dissectors/packet-frame.h>
#include <epan/show_exception.h>
#include <epan/dissectors/packet-dcerpc.h>
#include <epan/dissectors/packet-dcerpc-nt.h>
@ -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.

View File

@ -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 */
}

View File

@ -30,17 +30,17 @@
#include <glib.h>
#include <epan/packet.h>
#include <epan/etypes.h>
#include <epan/ppptypes.h>
#include <epan/show_exception.h>
#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 <epan/etypes.h>
#include <epan/ppptypes.h>
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);

View File

@ -29,16 +29,17 @@
#include <windows.h>
#endif
#include <glib.h>
#include <epan/packet.h>
#include <epan/show_exception.h>
#include <epan/timestamp.h>
#include "packet-frame.h"
#include <epan/prefs.h>
#include <epan/tap.h>
#include <epan/expert.h>
#include <epan/crypt/md5.h>
#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",

View File

@ -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
*/

View File

@ -31,17 +31,17 @@
#include <glib.h>
#include <epan/packet.h>
#include <epan/dissectors/packet-dcerpc.h>
#include <epan/dissectors/packet-gssapi.h>
#include <epan/dissectors/packet-frame.h>
#include <epan/conversation.h>
#include <epan/emem.h>
#include <epan/prefs.h>
#include <epan/reassemble.h>
#include <epan/asn1.h>
#include "packet-ber.h"
#include <epan/to_str.h>
#include <epan/show_exception.h>
#include <epan/dissectors/packet-ber.h>
#include <epan/dissectors/packet-dcerpc.h>
#include <epan/dissectors/packet-gssapi.h>
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);

View File

@ -35,7 +35,7 @@
#include <epan/reassemble.h>
#include <epan/golay.h>
#include <epan/iax2_codec_type.h>
#include <epan/dissectors/packet-frame.h>
#include <epan/show_exception.h>
#include <epan/asn1.h>
#include <epan/dissectors/packet-h245.h>
@ -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;

View File

@ -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) {

View File

@ -75,6 +75,7 @@
#include <epan/prefs.h>
#include <epan/uat.h>
#include <epan/strutil.h>
#include <epan/show_exception.h>
/* 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 */

View File

@ -27,9 +27,9 @@
#include <glib.h>
#include <epan/packet.h>
#include <epan/expert.h>
#include <epan/show_exception.h>
#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);
}

View File

@ -35,7 +35,7 @@
#include <epan/conversation.h>
#include <epan/prefs.h>
#include <epan/etypes.h>
#include <epan/dissectors/packet-frame.h>
#include <epan/show_exception.h>
#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);

View File

@ -26,11 +26,12 @@
#include <glib.h>
#include <epan/packet.h>
#include <epan/etypes.h>
#include <epan/show_exception.h>
#include "packet-isl.h"
#include "packet-eth.h"
#include "packet-tr.h"
#include "packet-frame.h"
#include <epan/etypes.h>
/*
* 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);

View File

@ -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;

View File

@ -104,7 +104,7 @@
#include <epan/emem.h>
#include <epan/oids.h>
#include <epan/strutil.h>
#include <epan/dissectors/packet-frame.h>
#include <epan/show_exception.h>
#include <epan/dissectors/packet-tcp.h>
#include <epan/dissectors/packet-windows-common.h>
#include <epan/dissectors/packet-dcerpc.h>

View File

@ -45,8 +45,8 @@
#include <epan/afn.h>
#include <epan/emem.h>
#include <epan/expert.h>
#include <epan/show_exception.h>
#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;

View File

@ -49,14 +49,14 @@
#include <glib.h>
#include <epan/packet.h>
#include <prefs.h>
#include <epan/prefs.h>
#include <epan/in_cksum.h>
#include <epan/etypes.h>
#include <epan/ipproto.h>
#include <show_exception.h>
#include "packet-ip.h"
#include "packet-rsvp.h"
#include "packet-frame.h"
static int proto_lmp = -1;

View File

@ -31,12 +31,13 @@
#include <epan/packet.h>
#include <epan/emem.h>
#include <epan/prefs.h>
#include <epan/strutil.h>
#include <epan/show_exception.h>
#include "packet-dns.h"
#include "packet-netbios.h"
#include "packet-tcp.h"
#include "packet-frame.h"
#include <epan/prefs.h>
#include <epan/strutil.h>
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;

View File

@ -29,8 +29,8 @@
#include <glib.h>
#include <epan/packet.h>
#include <epan/show_exception.h>
#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;
}

View File

@ -35,20 +35,20 @@
#include <glib.h>
#include <epan/packet.h>
#include "packet-windows-common.h"
#include "packet-smb-common.h"
#include "packet-frame.h"
#include <epan/asn1.h>
#include "packet-kerberos.h"
#include <epan/prefs.h>
#include <epan/emem.h>
#include <epan/tap.h>
#include <epan/expert.h>
#include <epan/show_exception.h>
#include <epan/crypt/rc4.h>
#include <epan/crypt/md4.h>
#include <epan/crypt/md5.h>
#include <epan/crypt/des.h>
#include "packet-windows-common.h"
#include "packet-smb-common.h"
#include "packet-kerberos.h"
#include "packet-dcerpc.h"
#include "packet-gssapi.h"
#include <wsutil/crc32.h>
@ -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;

View File

@ -36,8 +36,6 @@
#include <epan/packet.h>
#include <epan/dissectors/packet-tcp.h>
#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;

View File

@ -34,17 +34,18 @@
#include <epan/packet.h>
#include <epan/conversation.h>
#include <epan/emem.h>
#include "packet-rpc.h"
#include "packet-frame.h"
#include "packet-tcp.h"
#include <epan/prefs.h>
#include <epan/reassemble.h>
#include <epan/dissectors/rpc_defrag.h>
#include "packet-nfs.h"
#include <epan/tap.h>
#include <epan/strutil.h>
#include <epan/garrayfix.h>
#include <epan/emem.h>
#include <epan/show_exception.h>
#include "packet-rpc.h"
#include "packet-tcp.h"
#include <epan/dissectors/rpc_defrag.h>
#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

View File

@ -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);

View File

@ -290,9 +290,6 @@ extern value_string_ext scsi_asc_val_ext;
THROW(ScsiBoundsError); \
} \
} \
CATCH_ALL { \
RETHROW; \
} \
ENDTRY; \
}

View File

@ -59,14 +59,15 @@
#include <epan/tap.h>
#include <epan/ipproto.h>
#include <epan/addr_resolv.h>
#include "packet-sctp.h"
#include <epan/sctpppids.h>
#include <epan/emem.h>
#include <epan/expert.h>
#include <packet-frame.h>
#include <epan/show_exception.h>
#include <wsutil/crc32.h>
#include <epan/adler32.h>
#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;

View File

@ -59,11 +59,11 @@
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/tap.h>
#include <epan/rtp_pt.h>
#include <epan/show_exception.h>
#include "packet-sdp.h"
#include "packet-frame.h"
#include "packet-rtp.h"
#include <epan/rtp_pt.h>
#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) {

View File

@ -34,10 +34,10 @@
#include <epan/asn1.h>
#include <epan/conversation.h>
#include <epan/reassemble.h>
#include <epan/show_exception.h>
#include "packet-ber.h"
#include "packet-ses.h"
#include "packet-frame.h"
/* #include <epan/prefs.h> */
#include <epan/emem.h>

View File

@ -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).

View File

@ -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;

View File

@ -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;

View File

@ -41,11 +41,11 @@
#include <epan/oids.h>
#include <epan/asn1.h>
#include <epan/strutil.h>
#include <epan/show_exception.h>
#include <string.h>
#include "packet-ber.h"
#include "packet-tcap.h"
#include "packet-frame.h"
#include <epan/tcap-persistentdata.h>
#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;

View File

@ -36,14 +36,15 @@
#include <epan/follow.h>
#include <epan/prefs.h>
#include <epan/emem.h>
#include "packet-tcp.h"
#include "packet-frame.h"
#include <epan/show_exception.h>
#include <epan/conversation.h>
#include <epan/reassemble.h>
#include <epan/tap.h>
#include <epan/slab.h>
#include <epan/expert.h>
#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;

View File

@ -156,8 +156,7 @@
#include <epan/packet.h>
#include <epan/conversation.h>
#include <epan/strutil.h>
#include "packet-frame.h"
#include <epan/show_exception.h>
#include <epan/reassemble.h>
#include <epan/prefs.h>
#include <epan/emem.h>
@ -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;

View File

@ -30,13 +30,16 @@
#include "config.h"
#include <ctype.h>
#include <glib.h>
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/show_exception.h>
#include "packet-tpkt.h"
#include "packet-frame.h"
#include <epan/prefs.h>
#include <ctype.h>
/* 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;

View File

@ -48,6 +48,7 @@
#include <epan/packet.h>
#include <epan/emem.h>
#include <epan/expert.h>
#include <epan/show_exception.h>
/* 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))

View File

@ -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;

View File

@ -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;

View File

@ -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 */

View File

@ -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);

View File

@ -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

146
epan/show_exception.c Normal file
View File

@ -0,0 +1,146 @@
/* show_exception.c
*
* Routines to put exception information into the protocol tree
*
* $Id$
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* 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 <glib.h>
#include <epan/packet.h>
#include <epan/expert.h>
#include <epan/show_exception.h>
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)");
}
}

48
epan/show_exception.h Normal file
View File

@ -0,0 +1,48 @@
/* show_exception.h
*
* Routines to put exception information into the protocol tree
*
* $Id$
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* 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);

View File

@ -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);

View File

@ -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;

View File

@ -33,6 +33,8 @@
#include "wslua.h"
#include <epan/show_exception.h>
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;

View File

@ -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)