Wireshark-dev: [Wireshark-dev] 1.12.0rc2 : tshark crash when message is on 3 packets
From: wsgd <[email protected]>
Date: Mon, 16 Jun 2014 22:44:21 +0200
Hello,

My protocol (only to test this problem) specifications :
tcp port 20640
message is 5 bytes long



command line : tshark -r pb.cap  -T text -V
--> crash (see pb.1.12.0.txt)
**
ERROR:print.c:838:get_field_data: code should not be reached

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.



wireshark does not crash and display is ok
tshark 1.10.6 does not crash and display is ok (see pb.1.10.6.txt)


Plugin dissector code is into packet-tcp-5-bytes.c



Regards,
Olivier

--
Wireshark Generic Dissector http://wsgd.free.fr

Attachment: pb.pcap
Description: Binary data

Frame 1: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: 00:00:de:4b:da:02 (00:00:de:4b:da:02), Dst: 00:02:55:76:aa:eb (00:02:55:76:aa:eb)
Internet Protocol Version 4, Src: 172.16.3.19 (172.16.3.19), Dst: 172.16.3.18 (172.16.3.18)
Transmission Control Protocol, Src Port: 20640 (20640), Dst Port: 36179 (36179), Seq: 1, Ack: 1, Len: 4
Data (4 bytes)

0000  00 0f 00 16                                       ....
    Data: 000f0016
    [Length: 4]

Frame 2: 72 bytes on wire (576 bits), 72 bytes captured (576 bits)
Ethernet II, Src: 00:00:de:4b:da:02 (00:00:de:4b:da:02), Dst: 00:02:55:76:aa:eb (00:02:55:76:aa:eb)
Internet Protocol Version 4, Src: 172.16.3.19 (172.16.3.19), Dst: 172.16.3.18 (172.16.3.18)
Transmission Control Protocol, Src Port: 20640 (20640), Dst Port: 36179 (36179), Seq: 5, Ack: 1, Len: 18
[2 Reassembled TCP Segments (22 bytes): #1(4), #2(18)]
Data: 000f001600
Data: 0000008001
Data: 0000888888
Data: 8000a00004

Frame 3: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: 00:00:de:4b:da:02 (00:00:de:4b:da:02), Dst: 00:02:55:76:aa:eb (00:02:55:76:aa:eb)
Internet Protocol Version 4, Src: 172.16.3.19 (172.16.3.19), Dst: 172.16.3.18 (172.16.3.18)
Transmission Control Protocol, Src Port: 20640 (20640), Dst Port: 36179 (36179), Seq: 23, Ack: 1, Len: 4
[2 Reassembled TCP Segments (6 bytes): #2(2), #3(4)]
Data: 93e0001000

Frame 4: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: 00:00:de:4b:da:02 (00:00:de:4b:da:02), Dst: 00:02:55:76:aa:eb (00:02:55:76:aa:eb)
Internet Protocol Version 4, Src: 172.16.3.19 (172.16.3.19), Dst: 172.16.3.18 (172.16.3.18)
Transmission Control Protocol, Src Port: 20640 (20640), Dst Port: 36179 (36179), Seq: 27, Ack: 1, Len: 3
Data (4 bytes)

0000  07 03 01 01                                       ....
    Data: 07030101
    [Length: 4]

Frame 5: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: 00:00:de:4b:da:02 (00:00:de:4b:da:02), Dst: 00:02:55:76:aa:eb (00:02:55:76:aa:eb)
Internet Protocol Version 4, Src: 172.16.3.19 (172.16.3.19), Dst: 172.16.3.18 (172.16.3.18)
Transmission Control Protocol, Src Port: 20640 (20640), Dst Port: 36179 (36179), Seq: 30, Ack: 1, Len: 4
[3 Reassembled TCP Segments (8 bytes): #3(1), #4(3), #5(4)]
Data: 0703010100

Frame 6: 81 bytes on wire (648 bits), 81 bytes captured (648 bits)
Ethernet II, Src: 00:00:de:4b:da:02 (00:00:de:4b:da:02), Dst: 00:02:55:76:aa:eb (00:02:55:76:aa:eb)
Internet Protocol Version 4, Src: 172.16.3.19 (172.16.3.19), Dst: 172.16.3.18 (172.16.3.18)
Transmission Control Protocol, Src Port: 20640 (20640), Dst Port: 36179 (36179), Seq: 34, Ack: 1, Len: 27
[2 Reassembled TCP Segments (30 bytes): #5(3), #6(27)]
Data: 11001f0001
Data: 581d66f400
Data: 0000000000
Data: 0000060000
Data: 0004000400
Data: 1000000000

Frame 1: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: 00:00:de:4b:da:02 (00:00:de:4b:da:02), Dst: 00:02:55:76:aa:eb (00:02:55:76:aa:eb)
Internet Protocol Version 4, Src: 172.16.3.19 (172.16.3.19), Dst: 172.16.3.18 (172.16.3.18)
Transmission Control Protocol, Src Port: 20640 (20640), Dst Port: 36179 (36179), Seq: 1, Ack: 1, Len: 4
Data (4 bytes)

0000  00 0f 00 16                                       ....
    Data: 000f0016
    [Length: 4]

Frame 2: 72 bytes on wire (576 bits), 72 bytes captured (576 bits)
Ethernet II, Src: 00:00:de:4b:da:02 (00:00:de:4b:da:02), Dst: 00:02:55:76:aa:eb (00:02:55:76:aa:eb)
Internet Protocol Version 4, Src: 172.16.3.19 (172.16.3.19), Dst: 172.16.3.18 (172.16.3.18)
Transmission Control Protocol, Src Port: 20640 (20640), Dst Port: 36179 (36179), Seq: 5, Ack: 1, Len: 18
[2 Reassembled TCP Segments (22 bytes): #1(4), #2(18)]
Data: 000f001600
Data: 0000008001
Data: 0000888888
Data: 8000a00004

Frame 3: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: 00:00:de:4b:da:02 (00:00:de:4b:da:02), Dst: 00:02:55:76:aa:eb (00:02:55:76:aa:eb)
Internet Protocol Version 4, Src: 172.16.3.19 (172.16.3.19), Dst: 172.16.3.18 (172.16.3.18)
Transmission Control Protocol, Src Port: 20640 (20640), Dst Port: 36179 (36179), Seq: 23, Ack: 1, Len: 4
[2 Reassembled TCP Segments (6 bytes): #2(2), #3(4)]
Data: 93e0001000

Frame 4: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
Ethernet II, Src: 00:00:de:4b:da:02 (00:00:de:4b:da:02), Dst: 00:02:55:76:aa:eb (00:02:55:76:aa:eb)
Internet Protocol Version 4, Src: 172.16.3.19 (172.16.3.19), Dst: 172.16.3.18 (172.16.3.18)
Transmission Control Protocol, Src Port: 20640 (20640), Dst Port: 36179 (36179), Seq: 27, Ack: 1, Len: 3
Data (4 bytes)
#include "config.h"

#include <glib.h>
#include <epan/packet.h>
#include <epan/dissectors/packet-tcp.h>

void proto_register_tcp_5_bytes(void);
void proto_reg_handoff_tcp_5_bytes(void);

static int proto_tcp_5_bytes = -1;


static int hf_tcp_5_bytes_data_data = -1;

static gint ett_tcp_5_bytes = -1;

static int
dissect_tcp_5_bytes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
{
    guint offset = 0;
    while(offset < tvb_reported_length(tvb)) {
        const gint available = tvb_reported_length_remaining(tvb, offset);
        const gint len = 5;

        if( available < len ) {
            /* we ran out of data: ask for more */
            pinfo->desegment_offset = offset;
            pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
            return  offset;
        }

        col_set_str(pinfo->cinfo, COL_INFO, "tcp-5-bytes");

        if (tree) {
            proto_tree_add_item(tree, hf_tcp_5_bytes_data_data, tvb, offset, len, 0);
        }
        offset += (guint)len;
    }

    /* if we get here, then the end of the tvb coincided with the end of a
       string. Happy days. */
    return tvb_length(tvb);
}


void
proto_register_tcp_5_bytes(void)
{
    static hf_register_info hf[] = {
        { &hf_tcp_5_bytes_data_data,
          { "Data",          "tcp_5_bytes.data.data", FT_BYTES, BASE_NONE, NULL, 0x0,
                NULL, HFILL }},
    };

    static gint *ett[] = {
        &ett_tcp_5_bytes,
    };

    proto_tcp_5_bytes = proto_register_protocol("DG tcp_5_bytes Protocol",
                                            "tcp_5_bytes",
                                            "tcp_5_bytes");
    proto_register_field_array(proto_tcp_5_bytes, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_tcp_5_bytes(void)
{
    dissector_handle_t tcp_5_bytes_handle;

    tcp_5_bytes_handle = new_create_dissector_handle(dissect_tcp_5_bytes, proto_tcp_5_bytes);
    dissector_add_uint("tcp.port", 20640, tcp_5_bytes_handle);
}