epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-wap.c
blob6f74729477ab6a69c67856251490acfd87c506d6
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 #include "config.h"
18 #ifdef DEBUG
19 #include <stdio.h>
20 #endif
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.
36 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;
41 unsigned octet;
42 unsigned counter = 0;
44 #ifdef DEBUG
45 fprintf (stderr,
46 "dissect_wap: Starting tvb_get_uintvar at offset %d\n", offset);
47 #endif
49 do {
50 octet = tvb_get_uint8 (tvb, offset+counter);
52 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;
61 break;
64 #ifdef DEBUG
65 fprintf(stderr,
66 "dissect_wap: computing: octet is %d (0x%02x), count=%d, value=%d\n",
67 octet, octet, counter, value);
68 #endif
69 } while (octet & 0x80);
71 #ifdef DEBUG
72 fprintf (stderr,
73 "dissect_wap: Leaving tvb_get_uintvar count=%d, value=%u\n",
74 counter, value);
75 #endif
77 if (octetCount)
78 *octetCount = counter;
80 return value;
84 * Editor modelines - https://www.wireshark.org/tools/modelines.html
86 * Local variables:
87 * c-basic-offset: 4
88 * tab-width: 8
89 * indent-tabs-mode: nil
90 * End:
92 * vi: set shiftwidth=4 tabstop=8 expandtab:
93 * :indentSize=4:tabSize=8:noTabs=true: