aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-frame.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-02-27 22:43:54 +0000
committerGuy Harris <guy@alum.mit.edu>2013-02-27 22:43:54 +0000
commit6b629c4d92a7223c4930d9b22be1d9e32c375303 (patch)
treefbdbf4b1f847b8388e365010ee64e04413507bd0 /epan/dissectors/packet-frame.c
parent97a0ad8eab5b236f33113858ec62f15f82775f76 (diff)
downloadwireshark-6b629c4d92a7223c4930d9b22be1d9e32c375303.tar.gz
wireshark-6b629c4d92a7223c4930d9b22be1d9e32c375303.tar.bz2
wireshark-6b629c4d92a7223c4930d9b22be1d9e32c375303.zip
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
Diffstat (limited to 'epan/dissectors/packet-frame.c')
-rw-r--r--epan/dissectors/packet-frame.c126
1 files changed, 5 insertions, 121 deletions
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 <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;
@@ -580,99 +571,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)
{
static hf_register_info hf[] = {
@@ -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",