Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/epan/dissectors/packet-wap.c
Line
Count
Source (jump to first uncovered line)
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.1k
#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
17.9k
{
39
17.9k
    unsigned value   = 0, previous_value;
40
17.9k
    unsigned octet;
41
17.9k
    unsigned counter = 0;
42
43
17.9k
    ws_debug("Starting tvb_get_uintvar at offset %d", offset);
44
45
25.2k
    do {
46
25.2k
        octet = tvb_get_uint8 (tvb, offset+counter);
47
48
25.2k
        counter++;
49
50
25.2k
        previous_value = value;
51
25.2k
        value <<= 7;  /* Value only exists in 7 of the 8 bits */
52
25.2k
        value += (octet & 0x7F);
53
25.2k
        if (value < previous_value || value > MAX_WAP_UINTVAR) {
54
            /* overflow; clamp the value at UINT_MAX */
55
951
            proto_tree_add_expert(NULL, pinfo, ei, tvb, offset, counter);
56
951
            value = MAX_WAP_UINTVAR;
57
951
            break;
58
951
        }
59
60
24.3k
        ws_debug("computing: octet is %d (0x%02x), count=%d, value=%d",
61
24.3k
                 octet, octet, counter, value);
62
24.3k
    } while (octet & 0x80);
63
64
17.9k
    ws_debug(" Leaving tvb_get_uintvar count=%d, value=%u",
65
17.9k
            counter, value);
66
67
17.9k
    if (octetCount)
68
17.9k
        *octetCount = counter;
69
70
17.9k
    return value;
71
17.9k
}
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
 */