From f2246ebb65b7640ecf7e17a974ef4521427dca47 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 24 Jan 2000 03:33:35 +0000 Subject: [PATCH] Fix a bunch of dissectors to use "pi.captured_len" rather than "fd->cap_len" for the frame length - or to use macros such as "BYTES_ARE_IN_FRAME()", "IS_DATA_IN_FRAME()", and "END_OF_FRAME", which use "pi.captured_len" - so that they correctly handle frames where the actual data length of the packet is less than the size of the raw frame, e.g. with encapsulations such as ISL. svn path=/trunk/; revision=1530 --- packet-data.c | 8 ++++---- packet-icq.c | 7 ++----- packet-ipx.c | 6 +++--- packet-isis-hello.c | 8 ++++---- packet-isis-lsp.c | 8 ++++---- packet-isis-snp.c | 14 +++++++------- packet-isis.c | 18 +++++++++--------- packet-osi.c | 10 +++++----- packet-rsvp.c | 4 ++-- 9 files changed, 40 insertions(+), 43 deletions(-) diff --git a/packet-data.c b/packet-data.c index 1891e7651f..653ab246be 100644 --- a/packet-data.c +++ b/packet-data.c @@ -2,7 +2,7 @@ * Routines for raw data (default case) * Gilbert Ramirez * - * $Id: packet-data.c,v 1.13 2000/01/22 06:22:13 guy Exp $ + * $Id: packet-data.c,v 1.14 2000/01/24 03:33:35 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -41,9 +41,9 @@ int proto_data = -1; void -dissect_data(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { - - if (fd->cap_len > offset && tree) { +dissect_data(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) +{ + if (IS_DATA_IN_FRAME(offset) && tree) { proto_tree_add_item_format(tree, proto_data, offset, END_OF_FRAME, NULL, "Data (%d byte%s)", END_OF_FRAME, plurality(END_OF_FRAME, "", "s")); diff --git a/packet-icq.c b/packet-icq.c index c4b3fa54a5..dcac588ee6 100644 --- a/packet-icq.c +++ b/packet-icq.c @@ -1,7 +1,7 @@ /* packet-icq.c * Routines for ICQ packet disassembly * - * $Id: packet-icq.c,v 1.9 1999/12/05 22:59:55 guy Exp $ + * $Id: packet-icq.c,v 1.10 2000/01/24 03:33:34 guy Exp $ * * Ethereal - Network traffic analyzer * By Johan Feyaerts @@ -1991,12 +1991,9 @@ dissect_icqv5Client(const u_char *pd, guint16 pktsize = -1; /* The size of the ICQ content */ u_char decr_pd[1600]; /* Decrypted content, size should be dynamic */ - pktsize = fd->pkt_len - offset; + pktsize = END_OF_FRAME; /* First copy the memory, we don't want to overwrite the old content */ memcpy(decr_pd, &pd[offset], pktsize); - if (fd->pkt_len > fd->cap_len) { - pktsize -= (fd->pkt_len - fd->cap_len); - } if (pktsize>0x14) { key = get_v5key(decr_pd, pktsize); decrypt_v5(decr_pd, pktsize, key); diff --git a/packet-ipx.c b/packet-ipx.c index 8cce00579f..3883d84d32 100644 --- a/packet-ipx.c +++ b/packet-ipx.c @@ -2,7 +2,7 @@ * Routines for NetWare's IPX * Gilbert Ramirez * - * $Id: packet-ipx.c,v 1.47 2000/01/23 08:55:33 guy Exp $ + * $Id: packet-ipx.c,v 1.48 2000/01/24 03:33:33 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -638,7 +638,7 @@ dissect_ipxrip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { proto_tree_add_text(rip_tree, offset, 2, "Unknown RIP packet type"); } - for (cursor = offset + 2; cursor < fd->cap_len; cursor += 8) { + for (cursor = offset + 2; cursor < pi.captured_len; cursor += 8) { memcpy(&route.network, &pd[cursor], 4); route.hops = pntohs(&pd[cursor+4]); route.ticks = pntohs(&pd[cursor+6]); @@ -787,7 +787,7 @@ dissect_ipxsap(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { if (query.query_type == IPX_SAP_GENERAL_RESPONSE || query.query_type == IPX_SAP_NEAREST_RESPONSE) { /* responses */ - for (cursor = offset + 2; (cursor + 64) <= fd->cap_len; cursor += 64) { + for (cursor = offset + 2; (cursor + 64) <= pi.captured_len; cursor += 64) { server.server_type = pntohs(&pd[cursor]); memcpy(server.server_name, &pd[cursor+2], 48); memcpy(&server.server_network, &pd[cursor+50], 4); diff --git a/packet-isis-hello.c b/packet-isis-hello.c index 00b530f342..1710e05a7f 100644 --- a/packet-isis-hello.c +++ b/packet-isis-hello.c @@ -1,7 +1,7 @@ /* packet-isis-hello.c * Routines for decoding isis hello packets and their CLVs * - * $Id: packet-isis-hello.c,v 1.1 1999/12/15 04:34:17 guy Exp $ + * $Id: packet-isis-hello.c,v 1.2 2000/01/24 03:33:33 guy Exp $ * Stuart Stanley * * Ethereal - Network traffic analyzer @@ -427,10 +427,10 @@ isis_dissect_isis_hello(int hello_type, int header_length, hlen = sizeof(*ihp); } - if (fd->cap_len < (offset + hlen)) { + if (!BYTES_ARE_IN_FRAME(offset, hlen)) { isis_dissect_unknown(offset, hlen, tree, fd, "not enough capture data for header (%d vs %d)", - hlen, offset - fd->cap_len); + hlen, END_OF_FRAME); return; } @@ -438,7 +438,7 @@ isis_dissect_isis_hello(int hello_type, int header_length, if (tree) { ti = proto_tree_add_item(tree, proto_isis_hello, - offset, fd->cap_len - offset, NULL); + offset, END_OF_FRAME, NULL); hello_tree = proto_item_add_subtree(ti, ett_isis_hello); proto_tree_add_item_format(hello_tree, hf_isis_hello_circuit_reserved, diff --git a/packet-isis-lsp.c b/packet-isis-lsp.c index b2c3c916f0..a79b9d68c4 100644 --- a/packet-isis-lsp.c +++ b/packet-isis-lsp.c @@ -1,7 +1,7 @@ /* packet-isis-lsp.c * Routines for decoding isis lsp packets and their CLVs * - * $Id: packet-isis-lsp.c,v 1.2 2000/01/15 00:22:32 gram Exp $ + * $Id: packet-isis-lsp.c,v 1.3 2000/01/24 03:33:32 guy Exp $ * Stuart Stanley * * Ethereal - Network traffic analyzer @@ -790,10 +790,10 @@ isis_dissect_isis_lsp(int lsp_type, int header_length, hlen = sizeof(*ilp); - if (fd->cap_len < (offset + hlen)) { + if (!BYTES_ARE_IN_FRAME(offset, hlen)) { isis_dissect_unknown(offset, hlen, tree, fd, "not enough capture data for header (%d vs %d)", - hlen, offset - fd->cap_len); + hlen, END_OF_FRAME); return; } @@ -801,7 +801,7 @@ isis_dissect_isis_lsp(int lsp_type, int header_length, if (tree) { ti = proto_tree_add_item(tree, proto_isis_lsp, - offset, fd->cap_len - offset, NULL); + offset, END_OF_FRAME, NULL); lsp_tree = proto_item_add_subtree(ti, ett_isis_lsp); proto_tree_add_item(lsp_tree, hf_isis_lsp_pdu_length, offset, 2, pntohs(&ilp->isis_lsp_pdu_length)); diff --git a/packet-isis-snp.c b/packet-isis-snp.c index a75af4c5d5..b5853f3528 100644 --- a/packet-isis-snp.c +++ b/packet-isis-snp.c @@ -1,7 +1,7 @@ /* packet-isis-snp.c * Routines for decoding isis complete & partial SNP and their payload * - * $Id: packet-isis-snp.c,v 1.1 1999/12/15 04:34:19 guy Exp $ + * $Id: packet-isis-snp.c,v 1.2 2000/01/24 03:33:32 guy Exp $ * Stuart Stanley * * Ethereal - Network traffic analyzer @@ -242,10 +242,10 @@ isis_dissect_isis_csnp(int type, int header_length, const u_char *pd, hlen = sizeof(*ilp); - if (fd->cap_len < (offset + hlen)) { + if (!BYTES_ARE_IN_FRAME(offset, hlen)) { isis_dissect_unknown(offset, hlen, tree, fd, "not enough capture data for header (%d vs %d)", - hlen, offset - fd->cap_len); + hlen, END_OF_FRAME); return; } @@ -253,7 +253,7 @@ isis_dissect_isis_csnp(int type, int header_length, const u_char *pd, if (tree) { ti = proto_tree_add_item(tree, proto_isis_csnp, - offset, fd->cap_len - offset, NULL); + offset, END_OF_FRAME, NULL); csnp_tree = proto_item_add_subtree(ti, ett_isis_csnp); proto_tree_add_item(csnp_tree, hf_isis_csnp_pdu_length, offset, 2, pntohs(&ilp->isis_csnp_pdu_length)); @@ -316,10 +316,10 @@ isis_dissect_isis_psnp(int type, int header_length, const u_char *pd, hlen = sizeof(*ilp); - if (fd->cap_len < (offset + hlen)) { + if (!BYTES_ARE_IN_FRAME(offset, hlen)) { isis_dissect_unknown(offset, hlen, tree, fd, "not enough capture data for header (%d vs %d)", - hlen, offset - fd->cap_len); + hlen, END_OF_FRAME); return; } @@ -327,7 +327,7 @@ isis_dissect_isis_psnp(int type, int header_length, const u_char *pd, if (tree) { ti = proto_tree_add_item(tree, proto_isis_psnp, - offset, fd->cap_len - offset, NULL); + offset, END_OF_FRAME, NULL); psnp_tree = proto_item_add_subtree(ti, ett_isis_psnp); proto_tree_add_item(psnp_tree, hf_isis_psnp_pdu_length, offset, 2, pntohs(&ilp->isis_psnp_pdu_length)); diff --git a/packet-isis.c b/packet-isis.c index 9a0feee18e..ba54a2b88c 100644 --- a/packet-isis.c +++ b/packet-isis.c @@ -2,7 +2,7 @@ * Routines for ISO/OSI network and transport protocol packet disassembly, core * bits. * - * $Id: packet-isis.c,v 1.2 2000/01/13 06:07:52 guy Exp $ + * $Id: packet-isis.c,v 1.3 2000/01/24 03:33:31 guy Exp $ * Stuart Stanley * * Ethereal - Network traffic analyzer @@ -95,18 +95,18 @@ isis_dissect_unknown(int offset,guint length,proto_tree *tree,frame_data *fd, char *fmat, ...){ va_list ap; - if ( offset > fd->cap_len ) { + if ( !IS_DATA_IN_FRAME(offset) ) { /* * big oops They were off the end of the packet already. * Just ignore this one. */ return; } - if ( (offset + length) > fd->cap_len ) { + if ( !BYTES_ARE_IN_FRAME(offset, length) ) { /* * length will take us past eop. Truncate length. */ - length = offset - fd->cap_len; + length = END_OF_FRAME; } va_start(ap, fmat); @@ -178,17 +178,17 @@ dissect_isis(const u_char *pd, int offset, frame_data *fd, proto_item *ti; proto_tree *isis_tree = NULL; - if (fd->cap_len < offset + sizeof(*ihdr)) { + if (!BYTES_ARE_IN_FRAME(offset, sizeof(*ihdr))) { isis_dissect_unknown(offset, sizeof(*ihdr), tree, fd, "not enough capture data for header (%d vs %d)", - sizeof(*ihdr), offset - fd->cap_len); + sizeof(*ihdr), END_OF_FRAME); return; } ihdr = (isis_hdr_t *) &pd[offset]; if (ihdr->isis_version != ISIS_REQUIRED_VERSION){ - isis_dissect_unknown(offset, fd->cap_len, tree, fd, + isis_dissect_unknown(offset, END_OF_FRAME, tree, fd, "Unknown ISIS version (%d vs %d)", ihdr->isis_version, ISIS_REQUIRED_VERSION ); return; @@ -197,7 +197,7 @@ dissect_isis(const u_char *pd, int offset, frame_data *fd, if (tree) { ti = proto_tree_add_item(tree, proto_isis, offset, - fd->cap_len - offset, NULL ); + END_OF_FRAME, NULL ); isis_tree = proto_item_add_subtree(ti, ett_isis); proto_tree_add_item(isis_tree, hf_isis_irpd, offset, 1, ihdr->isis_irpd ); @@ -277,7 +277,7 @@ dissect_isis(const u_char *pd, int offset, frame_data *fd, ihdr->isis_header_length, pd, offset, fd, isis_tree); break; default: - isis_dissect_unknown(offset, offset - fd->cap_len, tree, fd, + isis_dissect_unknown(offset, END_OF_FRAME, tree, fd, "unknown ISIS packet type" ); } } /* dissect_isis */ diff --git a/packet-osi.c b/packet-osi.c index 891d5f71d4..1026af5dc2 100644 --- a/packet-osi.c +++ b/packet-osi.c @@ -1,7 +1,7 @@ /* packet-osi.c * Routines for ISO/OSI network and transport protocol packet disassembly * - * $Id: packet-osi.c,v 1.17 2000/01/20 19:16:33 guy Exp $ + * $Id: packet-osi.c,v 1.18 2000/01/24 03:33:31 guy Exp $ * Laurent Deniel * * Ethereal - Network traffic analyzer @@ -1354,7 +1354,7 @@ void dissect_cotp(const u_char *pd, int offset, frame_data *fd, int status = -1; if (((li = pd[offset + P_LI]) == 0) || - (offset + P_LI + li + 1 > fd->cap_len)) { + (!BYTES_ARE_IN_FRAME(offset, P_LI + li + 1))) { dissect_data(pd, offset, fd, tree); return; } @@ -1462,7 +1462,7 @@ void dissect_clnp(const u_char *pd, int offset, frame_data *fd, return; } - if (fd->cap_len < offset + sizeof(clnp)) { + if (!BYTES_ARE_IN_FRAME(offset, sizeof(clnp))) { dissect_data(pd, offset, fd, tree); return; } @@ -1510,7 +1510,7 @@ void dissect_clnp(const u_char *pd, int offset, frame_data *fd, /* stop here if header is not complete */ - if (fd->cap_len < offset + clnp.cnf_hdr_len) { + if (!BYTES_ARE_IN_FRAME(offset, clnp.cnf_hdr_len)) { dissect_data(pd, offset, fd, tree); return; } @@ -1577,7 +1577,7 @@ void dissect_clnp(const u_char *pd, int offset, frame_data *fd, offset = first_offset + clnp.cnf_hdr_len; - if (offset == fd->cap_len) + if (!IS_DATA_IN_FRAME(offset)) return; /* continue with COTP if any */ diff --git a/packet-rsvp.c b/packet-rsvp.c index 032f49aeaa..a6446bd6d4 100644 --- a/packet-rsvp.c +++ b/packet-rsvp.c @@ -3,7 +3,7 @@ * * (c) Copyright Ashok Narayanan * - * $Id: packet-rsvp.c,v 1.11 1999/12/13 19:59:29 gram Exp $ + * $Id: packet-rsvp.c,v 1.12 2000/01/24 03:33:30 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -422,7 +422,7 @@ dissect_rsvp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) while (len + sizeof(rsvp_header) < msg_length) { obj = (rsvp_object *)&pd[offset]; obj_length = pntohs(pd+offset); - if (offset + obj_length > fd->cap_len) { + if (!BYTES_ARE_IN_FRAME(offset, obj_length)) { proto_tree_add_text(rsvp_tree, offset, 1, "Further data not captured"); break;