From a5f4e7b85a035b234ca06b0c88ee89eda76d6524 Mon Sep 17 00:00:00 2001 From: Jeff Morriss Date: Mon, 2 Apr 2007 08:25:43 +0000 Subject: [PATCH] Make RX a new style dissector: return 0 if there isn't at least 28 bytes of message or if it receives an unknown Type. Add a check of tvb length to README.developer's cut-n-paste dissector code. svn path=/trunk/; revision=21300 --- doc/README.developer | 3 +++ epan/dissectors/packet-rx.c | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/README.developer b/doc/README.developer index a9a9203c3b..8a317cc7c2 100644 --- a/doc/README.developer +++ b/doc/README.developer @@ -733,6 +733,9 @@ dissect_PROTOABBREV(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * if someone analyzed that web server's traffic in Wireshark, would result * in Wireshark handing an HTTP packet to your dissector). For example: */ + /* Check that there's enough data */ + if (tvb_length(tvb) < /* your protocol's smallest packet size */) + return 0; /* Get some values from the packet header, probably using tvb_get_*() */ if ( /* these values are not possible in PROTONAME */ ) diff --git a/epan/dissectors/packet-rx.c b/epan/dissectors/packet-rx.c index 191c05db75..5f4bd72528 100644 --- a/epan/dissectors/packet-rx.c +++ b/epan/dissectors/packet-rx.c @@ -452,7 +452,7 @@ dissect_rx_flags(tvbuff_t *tvb, struct rxinfo *rxinfo, proto_tree *parent_tree, return offset; } -static void +static int dissect_rx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) { proto_tree *tree; @@ -463,6 +463,15 @@ dissect_rx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) guint32 seq, callnumber; guint16 serviceid; + /* Ensure we have enough data */ + if (tvb_length(tvb) < 28) + return 0; + + /* Make sure it's a known type */ + type = tvb_get_guint8(tvb, 20); + if (type == 0 || type == 10 || type == 11 || type == 12 || type > 13) + return 0; + if (check_col(pinfo->cinfo, COL_PROTOCOL)) col_set_str(pinfo->cinfo, COL_PROTOCOL, "RX"); if (check_col(pinfo->cinfo, COL_INFO)) @@ -582,6 +591,7 @@ dissect_rx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) break; } + return(tvb_length(tvb)); } void @@ -784,7 +794,7 @@ proto_reg_handoff_rx(void) /* Ports in the range UDP_PORT_RX_LOW to UDP_PORT_RX_HIGH are all used for various AFS services. */ - rx_handle = create_dissector_handle(dissect_rx, proto_rx); + rx_handle = new_create_dissector_handle(dissect_rx, proto_rx); for (port = UDP_PORT_RX_LOW; port <= UDP_PORT_RX_HIGH; port++) dissector_add("udp.port", port, rx_handle); dissector_add("udp.port", UDP_PORT_RX_AFS_BACKUPS, rx_handle);