Coverage Report

Created: 2026-01-10 06:17

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
490
static int tortureParseEndpointUrl(const uint8_t *data, size_t size) {
15
490
    const UA_String endpointUrl = {
16
490
        size, (UA_Byte* )(void*)data
17
490
    };
18
19
490
    UA_String hostname;
20
490
    UA_UInt16 port;
21
490
    UA_String path;
22
490
    UA_parseEndpointUrl(&endpointUrl, &hostname, &port, &path);
23
490
    return 0;
24
490
}
25
26
349
static int tortureParseEndpointUrlEthernet(const uint8_t *data, size_t size) {
27
349
    const UA_String endpointUrl = {
28
349
        size, (UA_Byte* )(void*)data
29
349
    };
30
31
349
    UA_String target;
32
349
    UA_UInt16 vid;
33
349
    UA_Byte prid;
34
349
    UA_parseEndpointUrlEthernet(&endpointUrl, &target, &vid, &prid);
35
349
    return 0;
36
349
}
37
38
/*
39
** Main entry point.  The fuzzer invokes this function with each
40
** fuzzed input.
41
*/
42
846
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
43
44
846
    if (!UA_memoryManager_setLimitFromLast4Bytes(data, size))
45
2
        return 0;
46
844
    size -= 4;
47
48
844
    if (size == 0)
49
1
        return 0;
50
51
    // use first byte to decide which function should be fuzzed
52
53
843
    const uint8_t select = data[0];
54
55
843
    const uint8_t *newData = &data[1];
56
843
    size_t  newSize = size-1;
57
58
843
    switch(select) {
59
490
        case 0:
60
490
            return tortureParseEndpointUrl(newData, newSize);
61
349
        case 1:
62
349
            return tortureParseEndpointUrlEthernet(newData, newSize);
63
4
        default:
64
4
            return 0;
65
843
    }
66
67
843
}