3 * Utility routines for WAP dissectors
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * WAP dissector based on original work by Ben Fowler
10 * Updated by Neil Hunter <neil.hunter@energis-squared.com>
11 * WTLS support by Alexandre P. Ferreira (Splice IP)
13 * SPDX-License-Identifier: GPL-2.0-or-later
22 #include <epan/packet.h>
23 #include "packet-wap.h"
26 * Accessor to retrieve variable length int as used in WAP protocol.
27 * The value is encoded in the lower 7 bits. If the top bit is set, then the
28 * value continues into the next byte.
29 * The octetCount parameter holds the number of bytes read in order to return
30 * the final value. Can be pre-initialised to start at offset+count.
32 * XXX This seems to be used exclusively for fetching size values. We should
33 * probably rename this to wap_get_checked_size or something along those lines.
35 #define MAX_WAP_UINTVAR (100 * 1000 * 1000) // Arbitrary. We need a large number that won't overflow a unsigned.
37 tvb_get_uintvar (tvbuff_t
*tvb
, unsigned offset
,
38 unsigned *octetCount
, packet_info
*pinfo
, expert_field
*ei
)
40 unsigned value
= 0, previous_value
;
46 "dissect_wap: Starting tvb_get_uintvar at offset %d\n", offset
);
50 octet
= tvb_get_uint8 (tvb
, offset
+counter
);
54 previous_value
= value
;
55 value
<<= 7; /* Value only exists in 7 of the 8 bits */
56 value
+= (octet
& 0x7F);
57 if (value
< previous_value
|| value
> MAX_WAP_UINTVAR
) {
58 /* overflow; clamp the value at UINT_MAX */
59 proto_tree_add_expert(NULL
, pinfo
, ei
, tvb
, offset
, counter
);
60 value
= MAX_WAP_UINTVAR
;
66 "dissect_wap: computing: octet is %d (0x%02x), count=%d, value=%d\n",
67 octet
, octet
, counter
, value
);
69 } while (octet
& 0x80);
73 "dissect_wap: Leaving tvb_get_uintvar count=%d, value=%u\n",
78 *octetCount
= counter
;
84 * Editor modelines - https://www.wireshark.org/tools/modelines.html
89 * indent-tabs-mode: nil
92 * vi: set shiftwidth=4 tabstop=8 expandtab:
93 * :indentSize=4:tabSize=8:noTabs=true: