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
16 #define WS_LOG_DOMAIN "packet-wap"
19 #include <wireshark.h>
21 #include <epan/packet.h>
22 #include "packet-wap.h"
25 * Accessor to retrieve variable length int as used in WAP protocol.
26 * The value is encoded in the lower 7 bits. If the top bit is set, then the
27 * value continues into the next byte.
28 * The octetCount parameter holds the number of bytes read in order to return
29 * the final value. Can be pre-initialised to start at offset+count.
31 * XXX This seems to be used exclusively for fetching size values. We should
32 * probably rename this to wap_get_checked_size or something along those lines.
34 #define MAX_WAP_UINTVAR (100 * 1000 * 1000) // Arbitrary. We need a large number that won't overflow a unsigned.
36 tvb_get_uintvar (tvbuff_t
*tvb
, unsigned offset
,
37 unsigned *octetCount
, packet_info
*pinfo
, expert_field
*ei
)
39 unsigned value
= 0, previous_value
;
43 ws_debug("Starting tvb_get_uintvar at offset %d", offset
);
46 octet
= tvb_get_uint8 (tvb
, offset
+counter
);
50 previous_value
= value
;
51 value
<<= 7; /* Value only exists in 7 of the 8 bits */
52 value
+= (octet
& 0x7F);
53 if (value
< previous_value
|| value
> MAX_WAP_UINTVAR
) {
54 /* overflow; clamp the value at UINT_MAX */
55 proto_tree_add_expert(NULL
, pinfo
, ei
, tvb
, offset
, counter
);
56 value
= MAX_WAP_UINTVAR
;
60 ws_debug("computing: octet is %d (0x%02x), count=%d, value=%d",
61 octet
, octet
, counter
, value
);
62 } while (octet
& 0x80);
64 ws_debug(" Leaving tvb_get_uintvar count=%d, value=%u",
68 *octetCount
= counter
;
74 * Editor modelines - https://www.wireshark.org/tools/modelines.html
79 * indent-tabs-mode: nil
82 * vi: set shiftwidth=4 tabstop=8 expandtab:
83 * :indentSize=4:tabSize=8:noTabs=true: