Coverage Report

Created: 2025-07-18 06:17

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