From 303a7cc58fbcb7674155f4060c00192ea2ef638b Mon Sep 17 00:00:00 2001 From: Jaap Keuter Date: Wed, 27 Jan 2021 21:06:11 +0000 Subject: [PATCH] ZVT: Use standard TCP segment reassemble support function Fixes #17177 (cherry picked from commit 616d44cbb651fd53273946fc04d4653aa69584fb) --- epan/dissectors/packet-zvt.c | 66 ++++++++++-------------------------- 1 file changed, 17 insertions(+), 49 deletions(-) diff --git a/epan/dissectors/packet-zvt.c b/epan/dissectors/packet-zvt.c index df74277814..7aaec34706 100644 --- a/epan/dissectors/packet-zvt.c +++ b/epan/dissectors/packet-zvt.c @@ -34,6 +34,7 @@ #include #include #include +#include "packet-tcp.h" /* special characters of the serial transport protocol */ #define STX 0x02 @@ -948,59 +949,26 @@ dissect_zvt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) return zvt_len; } +static guint get_zvt_message_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_) +{ + guint len = tvb_get_guint8(tvb, offset+2); + if (len == 0xFF) + if (tvb_captured_length_remaining(tvb, offset) >= 5) + len = tvb_get_letohs(tvb, offset+3) + 5; + else + len = 0; + else + len += 3; + + return len; +} static int dissect_zvt_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) { - gint offset = 0, zvt_len = 0, ret; - proto_item *zvt_ti; - proto_tree *zvt_tree; - - if (tvb_captured_length(tvb) < ZVT_APDU_MIN_LEN) { - if (pinfo->can_desegment) { - pinfo->desegment_offset = offset; - pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT; - return -1; - } - return zvt_len; - } - - if (!valid_ctrl_field(tvb, 0)) - return 0; /* reject the packet */ - - col_set_str(pinfo->cinfo, COL_PROTOCOL, "ZVT"); - col_clear(pinfo->cinfo, COL_INFO); - zvt_ti = proto_tree_add_protocol_format(tree, proto_zvt, - tvb, 0, -1, - "ZVT Kassenschnittstelle: Transport Protocol TCP/IP"); - zvt_tree = proto_item_add_subtree(zvt_ti, ett_zvt); - - while (tvb_captured_length_remaining(tvb, offset) > 0) { - ret = dissect_zvt_apdu(tvb, offset, pinfo, zvt_tree); - if (ret == 0) { - /* not a valid APDU - mark the bytes that we consumed and exit, give - other dissectors a chance to try the remaining - bytes */ - break; - } - else if (ret < 0) { - /* not enough data - ask the TCP layer for more */ - - if (pinfo->can_desegment) { - pinfo->desegment_offset = offset; - pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT; - } - break; - } - else { - offset += ret; - zvt_len += ret; - } - } - - proto_item_set_len(zvt_ti, zvt_len); - return zvt_len; + tcp_dissect_pdus(tvb, pinfo, tree, TRUE, ZVT_APDU_MIN_LEN, + get_zvt_message_len, dissect_zvt, data); + return tvb_captured_length(tvb); } static void