Coverage Report

Created: 2025-12-27 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-wap.c
Line
Count
Source
1
/* packet-wap.c
2
 *
3
 * Utility routines for WAP dissectors
4
 *
5
 * Wireshark - Network traffic analyzer
6
 * By Gerald Combs <gerald@wireshark.org>
7
 * Copyright 1998 Gerald Combs
8
 *
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)
12
 *
13
 * SPDX-License-Identifier: GPL-2.0-or-later
14
 */
15
16
0
#define WS_LOG_DOMAIN "packet-wap"
17
18
#include "config.h"
19
#include <wireshark.h>
20
21
#include <epan/packet.h>
22
#include "packet-wap.h"
23
24
/*
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.
30
 *
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.
33
 */
34
26.2k
#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)
38
16.3k
{
39
16.3k
    unsigned value   = 0, previous_value;
40
16.3k
    unsigned octet;
41
16.3k
    unsigned counter = 0;
42
43
16.3k
    ws_debug("Starting tvb_get_uintvar at offset %d", offset);
44
45
24.8k
    do {
46
24.8k
        octet = tvb_get_uint8 (tvb, offset+counter);
47
48
24.8k
        counter++;
49
50
24.8k
        previous_value = value;
51
24.8k
        value <<= 7;  /* Value only exists in 7 of the 8 bits */
52
24.8k
        value += (octet & 0x7F);
53
24.8k
        if (value < previous_value || value > MAX_WAP_UINTVAR) {
54
            /* overflow; clamp the value at UINT_MAX */
55
1.49k
            proto_tree_add_expert(NULL, pinfo, ei, tvb, offset, counter);
56
1.49k
            value = MAX_WAP_UINTVAR;
57
1.49k
            break;
58
1.49k
        }
59
60
23.4k
        ws_debug("computing: octet is %d (0x%02x), count=%d, value=%d",
61
23.4k
                 octet, octet, counter, value);
62
23.4k
    } while (octet & 0x80);
63
64
16.3k
    ws_debug(" Leaving tvb_get_uintvar count=%d, value=%u",
65
16.3k
            counter, value);
66
67
16.3k
    if (octetCount)
68
16.2k
        *octetCount = counter;
69
70
16.3k
    return value;
71
16.3k
}
72
73
/*
74
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
75
 *
76
 * Local variables:
77
 * c-basic-offset: 4
78
 * tab-width: 8
79
 * indent-tabs-mode: nil
80
 * End:
81
 *
82
 * vi: set shiftwidth=4 tabstop=8 expandtab:
83
 * :indentSize=4:tabSize=8:noTabs=true:
84
 */