Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-wap.c
blob9c011496fc82245c8d3bea8ae79eaa76e558fe44
1 /* packet-wap.c
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"
18 #include "config.h"
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.
35 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;
40 unsigned octet;
41 unsigned counter = 0;
43 ws_debug("Starting tvb_get_uintvar at offset %d", offset);
45 do {
46 octet = tvb_get_uint8 (tvb, offset+counter);
48 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;
57 break;
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",
65 counter, value);
67 if (octetCount)
68 *octetCount = counter;
70 return value;
74 * Editor modelines - https://www.wireshark.org/tools/modelines.html
76 * Local variables:
77 * c-basic-offset: 4
78 * tab-width: 8
79 * indent-tabs-mode: nil
80 * End:
82 * vi: set shiftwidth=4 tabstop=8 expandtab:
83 * :indentSize=4:tabSize=8:noTabs=true: