aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/file-pcap.c
diff options
context:
space:
mode:
authorPascal Quantin <pascal.quantin@gmail.com>2015-08-19 21:54:47 +0200
committerMichael Mann <mmann78@netscape.net>2015-08-20 11:43:43 +0000
commitff78d0ad03b4df5f891f1c0728b0eaf421e88e08 (patch)
tree6fe18f478e10c05beeab215750b496bd9a6f9102 /epan/dissectors/file-pcap.c
parent2046368574a825d3a9fcdbe53165d4966fda1db4 (diff)
file-pcap: differentiate captured length and reported length when calling next dissector and catch bound errors
Otherwise dissection will fail when analyzing a capture with a snap length set Change-Id: I764f48c624d0cc411b04ee62f8ecccaf6abb6f0c Reviewed-on: https://code.wireshark.org/review/10134 Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com> Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/dissectors/file-pcap.c')
-rw-r--r--epan/dissectors/file-pcap.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/epan/dissectors/file-pcap.c b/epan/dissectors/file-pcap.c
index b70a686086..30c60e4067 100644
--- a/epan/dissectors/file-pcap.c
+++ b/epan/dissectors/file-pcap.c
@@ -28,6 +28,8 @@
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/expert.h>
+#include <epan/exceptions.h>
+#include <epan/show_exception.h>
#include <epan/wmem/wmem.h>
#include <wiretap/wtap.h>
@@ -286,7 +288,7 @@ dissect_pcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
{
static const guint8 pcap_magic[] = { 0xA1, 0xB2, 0xC3, 0xD4 };
static const guint8 pcap_swapped_magic[] = { 0xD4, 0xC3, 0xB2, 0xA1 };
- gint offset = 0;
+ volatile gint offset = 0;
proto_tree *main_tree;
proto_item *main_item;
proto_tree *header_tree;
@@ -297,10 +299,11 @@ dissect_pcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
proto_item *timestamp_item;
proto_tree *packet_data_tree;
proto_item *packet_data_item;
- guint32 encoding;
+ volatile guint32 encoding;
+ guint32 origin_length;
guint32 length;
guint32 link_type;
- guint32 frame_number = 1;
+ volatile guint32 frame_number = 1;
nstime_t timestamp;
if (tvb_memeql(tvb, 0, pcap_magic, sizeof(pcap_magic)) &&
@@ -361,11 +364,10 @@ dissect_pcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
proto_tree_add_item(timestamp_tree, hf_pcap_packet_timestamp_usec, tvb, offset, 4, encoding);
offset += 4;
- proto_tree_add_item(packet_tree, hf_pcap_packet_included_length, tvb, offset, 4, encoding);
- length = tvb_get_guint32(tvb, offset, encoding);
+ proto_tree_add_item_ret_uint(packet_tree, hf_pcap_packet_included_length, tvb, offset, 4, encoding, &length);
offset += 4;
- proto_tree_add_item(packet_tree, hf_pcap_packet_origin_length, tvb, offset, 4, encoding);
+ proto_tree_add_item_ret_uint(packet_tree, hf_pcap_packet_origin_length, tvb, offset, 4, encoding, &origin_length);
offset += 4;
packet_data_item = proto_tree_add_item(packet_tree, hf_pcap_packet_data, tvb, offset, length, ENC_NA);
@@ -374,8 +376,15 @@ dissect_pcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_
pinfo->fd->num = frame_number;
pinfo->fd->abs_ts = timestamp;
- if (pref_dissect_next_layer)
- call_dissector_with_data(pcap_pseudoheader_handle, tvb_new_subset_length(tvb, offset, length), pinfo, packet_data_tree, &link_type);
+ if (pref_dissect_next_layer) {
+ TRY {
+ call_dissector_with_data(pcap_pseudoheader_handle, tvb_new_subset(tvb, offset, length, origin_length), pinfo, packet_data_tree, &link_type);
+ }
+ CATCH_BOUNDS_ERRORS {
+ show_exception(tvb, pinfo, packet_data_tree, EXCEPT_CODE, GET_MESSAGE);
+ }
+ ENDTRY;
+ }
offset += length;
proto_item_set_len(packet_item, 4 * 4 + length);