3 * Routines to put exception information into the protocol tree
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 2000 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <epan/packet.h>
28 #include <epan/exceptions.h>
29 #include <epan/expert.h>
30 #include <epan/prefs.h>
31 #include <epan/prefs-int.h>
32 #include <epan/show_exception.h>
33 #include <wsutil/ws_printf.h> /* ws_g_warning */
35 static int proto_short = -1;
36 static int proto_malformed = -1;
37 static int proto_unreassembled = -1;
39 static expert_field ei_malformed_dissector_bug = EI_INIT;
40 static expert_field ei_malformed_reassembly = EI_INIT;
41 static expert_field ei_malformed = EI_INIT;
44 register_show_exception(void)
46 static ei_register_info ei[] = {
47 { &ei_malformed_dissector_bug, { "_ws.malformed.dissector_bug", PI_MALFORMED, PI_ERROR, "Dissector bug", EXPFILL }},
48 { &ei_malformed_reassembly, { "_ws.malformed.reassembly", PI_MALFORMED, PI_ERROR, "Reassembly error", EXPFILL }},
49 { &ei_malformed, { "_ws.malformed.expert", PI_MALFORMED, PI_ERROR, "Malformed Packet (Exception occurred)", EXPFILL }},
52 expert_module_t* expert_malformed;
54 proto_short = proto_register_protocol("Short Frame", "Short frame", "_ws.short");
55 proto_malformed = proto_register_protocol("Malformed Packet",
56 "Malformed packet", "_ws.malformed");
57 proto_unreassembled = proto_register_protocol(
58 "Unreassembled Fragmented Packet",
59 "Unreassembled fragmented packet", "_ws.unreassembled");
61 expert_malformed = expert_register_protocol(proto_malformed);
62 expert_register_field_array(expert_malformed, ei, array_length(ei));
64 /* "Short Frame", "Malformed Packet", and "Unreassembled Fragmented
65 Packet" aren't really protocols, they're error indications;
66 disabling them makes no sense. */
67 proto_set_cant_toggle(proto_short);
68 proto_set_cant_toggle(proto_malformed);
69 proto_set_cant_toggle(proto_unreassembled);
73 show_exception(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
74 unsigned long exception, const char *exception_message)
76 static const char dissector_error_nomsg[] =
77 "Dissector writer didn't bother saying what the error was";
80 if (exception == ReportedBoundsError && pinfo->fragmented)
81 exception = FragmentBoundsError;
86 col_append_str(pinfo->cinfo, COL_INFO, "[SCSI transfer limited due to allocation_length too small]");
87 proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0,
88 "SCSI transfer limited due to allocation_length too small: %s truncated]", pinfo->current_proto);
89 /* Don't record ScsiBoundsError exceptions as expert events - they merely
90 * reflect a normal SCSI condition.
91 * (any case where it's caused by something else is a bug). */
96 gboolean display_info = TRUE;
97 module_t * frame_module = prefs_find_module("frame");
98 if (frame_module != NULL)
100 pref_t *display_pref = prefs_find_preference(frame_module, "disable_packet_size_limited_in_summary");
103 if (*display_pref->varp.boolp)
104 display_info = FALSE;
109 col_append_str(pinfo->cinfo, COL_INFO, "[Packet size limited during capture]");
110 proto_tree_add_protocol_format(tree, proto_short, tvb, 0, 0,
111 "[Packet size limited during capture: %s truncated]", pinfo->current_proto);
112 /* Don't record BoundsError exceptions as expert events - they merely
113 * reflect a capture done with a snapshot length too short to capture
115 * (any case where it's caused by something else is a bug). */
119 case FragmentBoundsError:
120 col_append_fstr(pinfo->cinfo, COL_INFO, "[Unreassembled Packet%s]", pinfo->noreassembly_reason);
121 proto_tree_add_protocol_format(tree, proto_unreassembled,
122 tvb, 0, 0, "[Unreassembled Packet%s: %s]",
123 pinfo->noreassembly_reason, pinfo->current_proto);
124 /* Don't record FragmentBoundsError exceptions as expert events - they merely
125 * reflect dissection done with reassembly turned off
126 * (any case where it's caused by something else is a bug). */
129 case ReportedBoundsError:
130 show_reported_bounds_error(tvb, pinfo, tree);
134 col_append_fstr(pinfo->cinfo, COL_INFO,
135 "[Dissector bug, protocol %s: %s]",
136 pinfo->current_proto,
137 exception_message == NULL ?
138 dissector_error_nomsg : exception_message);
139 item = proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
140 "[Dissector bug, protocol %s: %s]",
141 pinfo->current_proto,
142 exception_message == NULL ?
143 dissector_error_nomsg : exception_message);
144 ws_g_warning("Dissector bug, protocol %s, in packet %u: %s",
145 pinfo->current_proto, pinfo->num,
146 exception_message == NULL ?
147 dissector_error_nomsg : exception_message);
148 expert_add_info_format(pinfo, item, &ei_malformed_dissector_bug, "%s",
149 exception_message == NULL ?
150 dissector_error_nomsg : exception_message);
153 case ReassemblyError:
154 col_append_fstr(pinfo->cinfo, COL_INFO,
155 "[Reassembly error, protocol %s: %s]",
156 pinfo->current_proto,
157 exception_message == NULL ?
158 dissector_error_nomsg : exception_message);
159 item = proto_tree_add_protocol_format(tree, proto_malformed, tvb, 0, 0,
160 "[Reassembly error, protocol %s: %s]",
161 pinfo->current_proto,
162 exception_message == NULL ?
163 dissector_error_nomsg : exception_message);
164 expert_add_info_format(pinfo, item, &ei_malformed_reassembly, "%s",
165 exception_message == NULL ?
166 dissector_error_nomsg : exception_message);
170 /* XXX - we want to know, if an unknown exception passed until here, don't we? */
171 g_assert_not_reached();
176 show_reported_bounds_error(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
180 col_append_str(pinfo->cinfo, COL_INFO,
181 "[Malformed Packet]");
182 item = proto_tree_add_protocol_format(tree, proto_malformed,
183 tvb, 0, 0, "[Malformed Packet: %s]", pinfo->current_proto);
184 expert_add_info(pinfo, item, &ei_malformed);
188 * Editor modelines - http://www.wireshark.org/tools/modelines.html
193 * indent-tabs-mode: t
196 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
197 * :indentSize=8:tabSize=8:noTabs=false: