diff options
-rw-r--r-- | exceptions.h | 15 | ||||
-rw-r--r-- | packet-atm.c | 6 | ||||
-rw-r--r-- | packet-eth.c | 10 | ||||
-rw-r--r-- | packet-fddi.c | 4 | ||||
-rw-r--r-- | packet-isl.c | 4 | ||||
-rw-r--r-- | packet-llc.c | 6 | ||||
-rw-r--r-- | packet-tr.c | 6 | ||||
-rw-r--r-- | packet-vlan.c | 4 | ||||
-rw-r--r-- | packet.c | 15 | ||||
-rw-r--r-- | tvbuff.c | 83 | ||||
-rw-r--r-- | tvbuff.h | 10 |
11 files changed, 107 insertions, 56 deletions
diff --git a/exceptions.h b/exceptions.h index 07de983f4d..4fa1c53960 100644 --- a/exceptions.h +++ b/exceptions.h @@ -10,6 +10,7 @@ /* Ethereal's exceptions */ #define BoundsError 1 /* Index is out of range */ +#define ReportedBoundsError 2 /* Index is beyond reported length (not cap_len) */ /* Usage: * @@ -21,6 +22,10 @@ * code; * } * + * CATCH2(exception1, exception2) { + * code; + * } + * * CATCH_ALL { * code; * } @@ -48,6 +53,9 @@ * else if (x == 2) { * <CATCH(2) code> * } + * else if (x == 3 || x == 4) { + * <CATCH2(3,4) code> + * } * else { * <CATCH_ALL code> { * } @@ -84,7 +92,6 @@ #define TRY \ {\ except_t *exc; \ - int caught = 0; \ static const except_id_t catch_spec[] = { \ { XCEPT_GROUP_ETHEREAL, XCEPT_CODE_ANY } }; \ except_try_push(catch_spec, 1, &exc); \ @@ -99,14 +106,16 @@ #define CATCH(x) \ } \ else if (exc->except_id.except_code == (x)) { \ - caught = 1; /* user's code goes here */ +#define CATCH2(x,y) \ + } \ + else if (exc->except_id.except_code == (x) || exc->except_id.except_code == (y)) { \ + /* user's code goes here */ #define CATCH_ALL \ } \ else { \ - caught = 1; /* user's code goes here */ #define FINALLY \ diff --git a/packet-atm.c b/packet-atm.c index 658b0e3112..52faabfa6b 100644 --- a/packet-atm.c +++ b/packet-atm.c @@ -1,7 +1,7 @@ /* packet-atm.c * Routines for ATM packet disassembly * - * $Id: packet-atm.c,v 1.16 2000/05/15 06:22:05 gram Exp $ + * $Id: packet-atm.c,v 1.17 2000/05/16 04:44:10 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -375,7 +375,7 @@ dissect_lane(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { tvbuff_t *next_tvb; - next_tvb = tvb_new_subset(pi.compat_top_tvb, offset, -1); + next_tvb = tvb_new_subset(pi.compat_top_tvb, offset, -1, -1); if (check_col(fd, COL_PROTOCOL)) col_add_str(fd, COL_PROTOCOL, "ATM LANE"); @@ -717,7 +717,7 @@ dissect_atm(const u_char *pd, frame_data *fd, proto_tree *tree) /* Dissect as WTAP_ENCAP_ATM_RFC1483 */ /* The ATM iptrace capture that we have hows LLC at this point, * so that's what I'm calling */ - next_tvb = tvb_new_subset(pi.compat_top_tvb, offset, -1); + next_tvb = tvb_new_subset(pi.compat_top_tvb, offset, -1, -1); dissect_llc(next_tvb, &pi, tree); break; diff --git a/packet-eth.c b/packet-eth.c index 54e91271b8..fbe02aa878 100644 --- a/packet-eth.c +++ b/packet-eth.c @@ -1,7 +1,7 @@ /* packet-eth.c * Routines for ethernet packet disassembly * - * $Id: packet-eth.c,v 1.36 2000/05/15 06:22:05 gram Exp $ + * $Id: packet-eth.c,v 1.37 2000/05/16 04:44:11 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -251,15 +251,15 @@ dissect_eth(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) /* Give the next dissector only 'length' number of bytes */ if (etype <= IEEE_802_3_MAX_LEN) { TRY { - next_tvb = tvb_new_subset(pi.compat_top_tvb, eth_offset, etype); + next_tvb = tvb_new_subset(pi.compat_top_tvb, eth_offset, etype, etype); } - CATCH(BoundsError) { - next_tvb = tvb_new_subset(pi.compat_top_tvb, eth_offset, -1); + CATCH2(BoundsError, ReportedBoundsError) { + next_tvb = tvb_new_subset(pi.compat_top_tvb, eth_offset, -1, etype); } ENDTRY; } else { - next_tvb = tvb_new_subset(pi.compat_top_tvb, eth_offset, -1); + next_tvb = tvb_new_subset(pi.compat_top_tvb, eth_offset, -1, -1); } switch (ethhdr_type) { diff --git a/packet-fddi.c b/packet-fddi.c index 4268a8c37a..12e57741ea 100644 --- a/packet-fddi.c +++ b/packet-fddi.c @@ -3,7 +3,7 @@ * * Laurent Deniel <deniel@worldnet.fr> * - * $Id: packet-fddi.c,v 1.32 2000/05/11 22:04:16 gram Exp $ + * $Id: packet-fddi.c,v 1.33 2000/05/16 04:44:11 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -313,7 +313,7 @@ dissect_fddi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, } - next_tvb = tvb_new_subset(tvb, FDDI_HEADER_SIZE, -1); + next_tvb = tvb_new_subset(tvb, FDDI_HEADER_SIZE, -1, -1); switch (fc) { diff --git a/packet-isl.c b/packet-isl.c index 9bd1fa5dd1..55c679e0e5 100644 --- a/packet-isl.c +++ b/packet-isl.c @@ -1,7 +1,7 @@ /* packet-isl.c * Routines for Cisco ISL Ethernet header disassembly * - * $Id: packet-isl.c,v 1.9 2000/05/15 06:22:06 gram Exp $ + * $Id: packet-isl.c,v 1.10 2000/05/16 04:44:11 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -225,7 +225,7 @@ dissect_isl(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) pd[offset+30]); proto_tree_add_item(fh_tree, hf_isl_esize, NullTVB, offset+16, 1, pd[offset+30]); - next_tvb = tvb_new_subset(pi.compat_top_tvb, offset+31, -1); + next_tvb = tvb_new_subset(pi.compat_top_tvb, offset+31, -1, -1); dissect_tr(next_tvb, &pi, tree); break; diff --git a/packet-llc.c b/packet-llc.c index a9bac08fd0..daf391eb4c 100644 --- a/packet-llc.c +++ b/packet-llc.c @@ -2,7 +2,7 @@ * Routines for IEEE 802.2 LLC layer * Gilbert Ramirez <gram@xiexie.org> * - * $Id: packet-llc.c,v 1.59 2000/05/12 05:06:26 gram Exp $ + * $Id: packet-llc.c,v 1.60 2000/05/16 04:44:12 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -342,7 +342,7 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) oui); } - next_tvb = tvb_new_subset(tvb, 8, -1); + next_tvb = tvb_new_subset(tvb, 8, -1, -1); tvb_compat(next_tvb, &pd, &offset); switch (oui) { @@ -432,7 +432,7 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) ); } - next_tvb = tvb_new_subset(tvb, llc_header_len, -1); + next_tvb = tvb_new_subset(tvb, llc_header_len, -1, -1); if (XDLC_IS_INFORMATION(control)) { tvb_compat(tvb, &pd, &offset); /* non-SNAP */ diff --git a/packet-tr.c b/packet-tr.c index a162647e11..afcce25d43 100644 --- a/packet-tr.c +++ b/packet-tr.c @@ -2,7 +2,7 @@ * Routines for Token-Ring packet disassembly * Gilbert Ramirez <gram@xiexie.org> * - * $Id: packet-tr.c,v 1.40 2000/05/15 06:22:06 gram Exp $ + * $Id: packet-tr.c,v 1.41 2000/05/16 04:44:12 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -336,7 +336,7 @@ dissect_tr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if ((x = check_for_old_linux_tvb((tvbuff_t*) tvb))) { /* Actually packet starts x bytes into what we have got but with all source routing compressed. See comment above */ - tr_tvb = tvb_new_subset((tvbuff_t*) tvb, x, -1); + tr_tvb = tvb_new_subset((tvbuff_t*) tvb, x, -1, -1); } else { tr_tvb = tvb; @@ -518,7 +518,7 @@ dissect_tr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) - next_tvb = tvb_new_subset(tr_tvb, TR_MIN_HEADER_LEN + actual_rif_bytes + fixoffset, -1); + next_tvb = tvb_new_subset(tr_tvb, TR_MIN_HEADER_LEN + actual_rif_bytes + fixoffset, -1, -1); tvb_compat(next_tvb, &next_pd, &next_offset); /* The package is either MAC or LLC */ diff --git a/packet-vlan.c b/packet-vlan.c index d747a855b4..67a4692f4b 100644 --- a/packet-vlan.c +++ b/packet-vlan.c @@ -1,7 +1,7 @@ /* packet-vlan.c * Routines for VLAN 802.1Q ethernet header disassembly * - * $Id: packet-vlan.c,v 1.12 2000/05/11 22:04:17 gram Exp $ + * $Id: packet-vlan.c,v 1.13 2000/05/16 04:44:13 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -98,7 +98,7 @@ dissect_vlan(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { proto_tree_add_item(vlan_tree, hf_vlan_id, NullTVB, offset, 2, tci); } - next_tvb = tvb_new_subset(pi.compat_top_tvb, offset+4, -1); + next_tvb = tvb_new_subset(pi.compat_top_tvb, offset+4, -1, -1); /* XXX - like dissect_eth() */ if ( encap_proto <= IEEE_802_3_MAX_LEN) { if ( pd[offset+4] == 0xff && pd[offset+5] == 0xff ) { dissect_ipx(pd,offset+4,fd,tree); @@ -1,7 +1,7 @@ /* packet.c * Routines for packet disassembly * - * $Id: packet.c,v 1.82 2000/05/15 06:22:07 gram Exp $ + * $Id: packet.c,v 1.83 2000/05/16 04:44:13 gram Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -104,6 +104,8 @@ static int hf_frame_time_delta = -1; static int hf_frame_number = -1; static int hf_frame_packet_len = -1; static int hf_frame_capture_len = -1; +static int proto_short = -1; +static int proto_malformed = -1; static gint ett_frame = -1; @@ -1165,7 +1167,7 @@ dissect_packet(const u_char *pd, frame_data *fd, proto_tree *tree) pi.len = fd->pkt_len; pi.captured_len = fd->cap_len; - tvb = tvb_new_real_data(pd, fd->cap_len); + tvb = tvb_new_real_data(pd, fd->cap_len, -1); pi.fd = fd; pi.compat_top_tvb = tvb; @@ -1214,7 +1216,12 @@ dissect_packet(const u_char *pd, frame_data *fd, proto_tree *tree) } } CATCH(BoundsError) { - proto_tree_add_text(tree, NullTVB, 0, 0, "[Short Frame: %s]", pi.current_proto ); + proto_tree_add_protocol_format(tree, proto_short, NullTVB, 0, 0, + "[Short Frame: %s]", pi.current_proto ); + } + CATCH(ReportedBoundsError) { + proto_tree_add_protocol_format(tree, proto_malformed, NullTVB, 0, 0, + "[Malformed Frame: %s]", pi.current_proto ); } ENDTRY; @@ -1313,6 +1320,8 @@ proto_register_frame(void) proto_register_field_array(proto_frame, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); + proto_short = proto_register_protocol("Short Frame", "short"); + proto_malformed = proto_register_protocol("Malformed Frame", "malformed"); register_init_routine(&packet_init_protocol); } @@ -9,7 +9,7 @@ * the data of a backing tvbuff, or can be a composite of * other tvbuffs. * - * $Id: tvbuff.c,v 1.2 2000/05/15 04:37:27 gram Exp $ + * $Id: tvbuff.c,v 1.3 2000/05/16 04:44:14 gram Exp $ * * Copyright (c) 2000 by Gilbert Ramirez <gram@xiexie.org> * @@ -121,6 +121,9 @@ struct tvbuff { /* Length of virtual buffer (and/or real_data). */ guint length; + /* Reported length. */ + gint reported_length; + /* Offset from beginning of first TVBUFF_REAL. */ gint raw_offset; @@ -163,6 +166,7 @@ tvb_init(tvbuff_t *tvb, tvbuff_type type) tvb->initialized = FALSE; tvb->usage_count = 1; tvb->length = 0; + tvb->reported_length = 0; tvb->free_cb = NULL; tvb->real_data = NULL; tvb->raw_offset = -1; @@ -298,23 +302,25 @@ tvb_set_free_cb(tvbuff_t* tvb, tvbuff_free_cb_t func) } void -tvb_set_real_data(tvbuff_t* tvb, const guint8* data, guint length) +tvb_set_real_data(tvbuff_t* tvb, const guint8* data, guint length, gint reported_length) { g_assert(tvb->type == TVBUFF_REAL_DATA); g_assert(!tvb->initialized); + g_assert(reported_length >= -1); - tvb->real_data = (gpointer) data; - tvb->length = length; - tvb->initialized = TRUE; + tvb->real_data = (gpointer) data; + tvb->length = length; + tvb->reported_length = reported_length; + tvb->initialized = TRUE; } tvbuff_t* -tvb_new_real_data(const guint8* data, guint length) +tvb_new_real_data(const guint8* data, guint length, gint reported_length) { tvbuff_t *tvb; tvb = tvb_new(TVBUFF_REAL_DATA); - tvb_set_real_data(tvb, data, length); + tvb_set_real_data(tvb, data, length, reported_length); return tvb; } @@ -326,7 +332,7 @@ tvb_new_real_data(const guint8* data, guint length) * No exception is thrown. */ static gboolean compute_offset_length(tvbuff_t *tvb, gint offset, gint length, - guint *offset_ptr, guint *length_ptr) + guint *offset_ptr, guint *length_ptr, int *exception) { g_assert(offset_ptr); g_assert(length_ptr); @@ -335,7 +341,16 @@ compute_offset_length(tvbuff_t *tvb, gint offset, gint length, if (offset >= 0) { *offset_ptr = offset; } + else if ((tvb->reported_length > -1) && -offset > tvb->reported_length) { + if (exception) { + *exception = ReportedBoundsError; + } + return FALSE; + } else if (-offset > tvb->length) { + if (exception) { + *exception = BoundsError; + } return FALSE; } else { @@ -357,18 +372,33 @@ compute_offset_length(tvbuff_t *tvb, gint offset, gint length, static gboolean check_offset_length_no_exception(tvbuff_t *tvb, gint offset, gint length, - guint *offset_ptr, guint *length_ptr) + guint *offset_ptr, guint *length_ptr, int *exception) { g_assert(tvb->initialized); - if (!compute_offset_length(tvb, offset, length, offset_ptr, length_ptr)) { + if (!compute_offset_length(tvb, offset, length, offset_ptr, length_ptr, exception)) { return FALSE; } if (*offset_ptr + *length_ptr <= tvb->length) { return TRUE; } + else if (tvb->reported_length == -1) { + if (exception) { + *exception = BoundsError; + } + return FALSE; + } + else if (*offset_ptr + *length_ptr <= tvb->reported_length) { + if (exception) { + *exception = BoundsError; + } + return FALSE; + } else { + if (exception) { + *exception = ReportedBoundsError; + } return FALSE; } @@ -382,8 +412,11 @@ static void check_offset_length(tvbuff_t *tvb, gint offset, gint length, guint *offset_ptr, guint *length_ptr) { - if (!check_offset_length_no_exception(tvb, offset, length, offset_ptr, length_ptr)) { - THROW(BoundsError); + int exception = 0; + + if (!check_offset_length_no_exception(tvb, offset, length, offset_ptr, length_ptr, &exception)) { + g_assert(exception > 0); + THROW(exception); } return; } @@ -396,7 +429,7 @@ add_to_used_in_list(tvbuff_t *tvb, tvbuff_t *used_in) void tvb_set_subset(tvbuff_t *tvb, tvbuff_t *backing, - gint backing_offset, gint backing_length) + gint backing_offset, gint backing_length, gint reported_length) { g_assert(tvb->type == TVBUFF_SUBSET); g_assert(!tvb->initialized); @@ -406,9 +439,10 @@ tvb_set_subset(tvbuff_t *tvb, tvbuff_t *backing, &tvb->tvbuffs.subset.length); tvb_increment_usage_count(backing, 1); - tvb->tvbuffs.subset.tvb = backing; - tvb->length = tvb->tvbuffs.subset.length; - tvb->initialized = TRUE; + tvb->tvbuffs.subset.tvb = backing; + tvb->length = tvb->tvbuffs.subset.length; + tvb->reported_length = reported_length; + tvb->initialized = TRUE; add_to_used_in_list(backing, tvb); /* Optimization. If the backing buffer has a pointer to contiguous, real data, @@ -420,12 +454,12 @@ tvb_set_subset(tvbuff_t *tvb, tvbuff_t *backing, tvbuff_t* -tvb_new_subset(tvbuff_t *backing, gint backing_offset, gint backing_length) +tvb_new_subset(tvbuff_t *backing, gint backing_offset, gint backing_length, gint reported_length) { tvbuff_t *tvb; tvb = tvb_new(TVBUFF_SUBSET); - tvb_set_subset(tvb, backing, backing_offset, backing_length); + tvb_set_subset(tvb, backing, backing_offset, backing_length, reported_length); return tvb; } @@ -503,8 +537,7 @@ tvb_length_remaining(tvbuff_t *tvb, gint offset) g_assert(tvb->initialized); - if (compute_offset_length(tvb, offset, -1, - &abs_offset, &abs_length)) { + if (compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length, NULL)) { return abs_length; } else { @@ -523,7 +556,7 @@ tvb_bytes_exist(tvbuff_t *tvb, gint offset, gint length) g_assert(tvb->initialized); - if (!compute_offset_length(tvb, offset, length, &abs_offset, &abs_length)) + if (!compute_offset_length(tvb, offset, length, &abs_offset, &abs_length, NULL)) return FALSE; if (abs_offset + abs_length <= tvb->length) { @@ -540,7 +573,7 @@ tvb_offset_exists(tvbuff_t *tvb, gint offset) guint abs_offset, abs_length; g_assert(tvb->initialized); - if (compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length)) { + if (compute_offset_length(tvb, offset, -1, &abs_offset, &abs_length, NULL)) { return TRUE; } else { @@ -635,7 +668,7 @@ composite_ensure_contiguous(tvbuff_t *tvb, guint abs_offset, guint abs_length) g_assert(member_tvb); if (check_offset_length_no_exception(member_tvb, abs_offset - composite->start_offsets[i], - abs_length, &member_offset, &member_length)) { + abs_length, &member_offset, &member_length, NULL)) { g_assert(!tvb->real_data); return ensure_contiguous(member_tvb, member_offset, member_length); @@ -706,7 +739,7 @@ composite_memcpy(tvbuff_t *tvb, guint8* target, guint abs_offset, guint abs_leng g_assert(member_tvb); if (check_offset_length_no_exception(member_tvb, abs_offset - composite->start_offsets[i], - abs_length, &member_offset, &member_length)) { + abs_length, &member_offset, &member_length, NULL)) { g_assert(!tvb->real_data); return tvb_memcpy(member_tvb, target, member_offset, member_length); @@ -718,7 +751,7 @@ composite_memcpy(tvbuff_t *tvb, guint8* target, guint abs_offset, guint abs_leng * until we have copied all data. */ retval = compute_offset_length(member_tvb, abs_offset - composite->start_offsets[i], -1, - &member_offset, &member_length); + &member_offset, &member_length, NULL); g_assert(retval); tvb_memcpy(member_tvb, target, member_offset, member_length); @@ -9,7 +9,7 @@ * the data of a backing tvbuff, or can be a composite of * other tvbuffs. * - * $Id: tvbuff.h,v 1.2 2000/05/15 04:37:27 gram Exp $ + * $Id: tvbuff.h,v 1.3 2000/05/16 04:44:14 gram Exp $ * * Copyright (c) 2000 by Gilbert Ramirez <gram@xiexie.org> * @@ -119,10 +119,10 @@ void tvb_set_free_cb(tvbuff_t*, tvbuff_free_cb_t); /* Sets parameters for TVBUFF_REAL_DATA */ -void tvb_set_real_data(tvbuff_t*, const guint8* data, guint length); +void tvb_set_real_data(tvbuff_t*, const guint8* data, guint length, gint reported_length); /* Combination of tvb_new() and tvb_set_real_data() */ -tvbuff_t* tvb_new_real_data(const guint8* data, guint length); +tvbuff_t* tvb_new_real_data(const guint8* data, guint length, gint reported_length); /* Define the subset of the backing buffer to use. @@ -138,11 +138,11 @@ tvbuff_t* tvb_new_real_data(const guint8* data, guint length); * Will throw BoundsError if 'backing_offset'/'length' * is beyond the bounds of the backing tvbuff. */ void tvb_set_subset(tvbuff_t* tvb, tvbuff_t* backing, - gint backing_offset, gint backing_length); + gint backing_offset, gint backing_length, gint reported_length); /* Combination of tvb_new() and tvb_set_subset() */ tvbuff_t* tvb_new_subset(tvbuff_t* backing, - gint backing_offset, gint backing_length); + gint backing_offset, gint backing_length, gint reported_length); /* Both tvb_composite_append and tvb_composite_prepend can throw |