Coverage Report

Created: 2026-01-17 07:04

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