Coverage Report

Created: 2026-10-03 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open62541/tests/fuzz/fuzz_src_ua_util.cc
Line
Count
Source
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
 *
5
 *    Copyright 2019 (c) fortiss (Author: Stefan Profanter)
6
 */
7
8
9
#include "custom_memory_manager.h"
10
11
#include <open62541/util.h>
12
13
14
984
static int tortureParseEndpointUrl(const uint8_t *data, size_t size) {
15
984
    const UA_String endpointUrl = {
16
984
        size, (UA_Byte* )(void*)data
17
984
    };
18
19
984
    UA_String hostname;
20
984
    UA_UInt16 port;
21
984
    UA_String path;
22
984
    UA_parseEndpointUrl(&endpointUrl, &hostname, &port, &path);
23
984
    return 0;
24
984
}
25
26
742
static int tortureParseEndpointUrlEthernet(const uint8_t *data, size_t size) {
27
742
    const UA_String endpointUrl = {
28
742
        size, (UA_Byte* )(void*)data
29
742
    };
30
31
742
    UA_String target;
32
742
    UA_UInt16 vid;
33
742
    UA_Byte prid;
34
742
    UA_parseEndpointUrlEthernet(&endpointUrl, &target, &vid, &prid);
35
742
    return 0;
36
742
}
37
38
/*
39
** Main entry point.  The fuzzer invokes this function with each
40
** fuzzed input.
41
*/
42
1.73k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
43
44
1.73k
    if (!UA_memoryManager_setLimitFromLast4Bytes(data, size))
45
4
        return 0;
46
1.73k
    size -= 4;
47
48
1.73k
    if (size == 0)
49
2
        return 0;
50
51
    // use first byte to decide which function should be fuzzed
52
53
1.73k
    const uint8_t select = data[0];
54
55
1.73k
    const uint8_t *newData = &data[1];
56
1.73k
    size_t  newSize = size-1;
57
58
1.73k
    switch(select) {
59
984
        case 0:
60
984
            return tortureParseEndpointUrl(newData, newSize);
61
742
        case 1:
62
742
            return tortureParseEndpointUrlEthernet(newData, newSize);
63
4
        default:
64
4
            return 0;
65
1.73k
    }
66
67
1.73k
}