Coverage Report

Created: 2026-05-30 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open62541_15/tests/fuzz/fuzz_parse_string.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
#include <cstdint>
6
#include <cstddef>
7
#include <cstring>
8
9
#include <open62541/config.h>
10
#include <open62541/types.h>
11
#include <open62541/util.h>
12
13
extern "C" int
14
5.70k
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
15
5.70k
    if(size <= 1)
16
2
        return 0;
17
18
    /* Use the first byte as a selector to choose which parsing function to fuzz */
19
5.70k
    uint8_t selector = data[0];
20
5.70k
    const uint8_t *payload = data + 1;
21
5.70k
    size_t payload_size = size - 1;
22
23
5.70k
    UA_String str;
24
5.70k
    UA_StatusCode retval = UA_ByteString_allocBuffer(&str, payload_size);
25
5.70k
    if(retval != UA_STATUSCODE_GOOD)
26
0
        return 0;
27
5.70k
    memcpy(str.data, payload, payload_size);
28
29
5.70k
    switch(selector % 8) {
30
410
    case 0: {
31
410
        UA_NodeId id;
32
410
        UA_NodeId_init(&id);
33
410
        UA_NodeId_parse(&id, str);
34
410
        UA_NodeId_clear(&id);
35
410
        break;
36
0
    }
37
1.39k
    case 1: {
38
1.39k
        UA_DateTime dt;
39
1.39k
        UA_DateTime_parse(&dt, str);
40
1.39k
        break;
41
0
    }
42
259
    case 2: {
43
259
        UA_Guid guid;
44
259
        UA_Guid_init(&guid);
45
259
        UA_Guid_parse(&guid, str);
46
259
        break;
47
0
    }
48
861
    case 3: {
49
861
        UA_ExpandedNodeId enid;
50
861
        UA_ExpandedNodeId_init(&enid);
51
861
        UA_ExpandedNodeId_parse(&enid, str);
52
861
        UA_ExpandedNodeId_clear(&enid);
53
861
        break;
54
0
    }
55
264
    case 4: {
56
264
        UA_QualifiedName qn;
57
264
        UA_QualifiedName_init(&qn);
58
264
        UA_QualifiedName_parse(&qn, str);
59
264
        UA_QualifiedName_clear(&qn);
60
264
        break;
61
0
    }
62
1.16k
    case 5: {
63
1.16k
        UA_RelativePath rp;
64
1.16k
        UA_RelativePath_init(&rp);
65
1.16k
        UA_StatusCode ret = UA_RelativePath_parse(&rp, str);
66
1.16k
        if(ret == UA_STATUSCODE_GOOD) {
67
739
            UA_String printed = UA_STRING_NULL;
68
739
            UA_RelativePath_print(&rp, &printed);
69
739
            UA_String_clear(&printed);
70
739
        }
71
1.16k
        UA_RelativePath_clear(&rp);
72
1.16k
        break;
73
0
    }
74
666
    case 6: {
75
666
        UA_SimpleAttributeOperand sao;
76
666
        UA_SimpleAttributeOperand_init(&sao);
77
666
        UA_SimpleAttributeOperand_parse(&sao, str);
78
666
        UA_SimpleAttributeOperand_clear(&sao);
79
666
        break;
80
0
    }
81
680
    case 7: {
82
680
        UA_ReadValueId rvi;
83
680
        UA_ReadValueId_init(&rvi);
84
680
        UA_ReadValueId_parse(&rvi, str);
85
680
        UA_ReadValueId_clear(&rvi);
86
680
        break;
87
0
    }
88
0
    default: break;
89
5.70k
    }
90
91
5.70k
    UA_String_clear(&str);
92
5.70k
    return 0;
93
5.70k
}