Coverage Report

Created: 2026-06-09 06:15

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.81k
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
15
5.81k
    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.81k
    uint8_t selector = data[0];
20
5.81k
    const uint8_t *payload = data + 1;
21
5.81k
    size_t payload_size = size - 1;
22
23
5.81k
    UA_String str;
24
5.81k
    UA_StatusCode retval = UA_ByteString_allocBuffer(&str, payload_size);
25
5.81k
    if(retval != UA_STATUSCODE_GOOD)
26
0
        return 0;
27
5.81k
    memcpy(str.data, payload, payload_size);
28
29
5.81k
    switch(selector % 8) {
30
418
    case 0: {
31
418
        UA_NodeId id;
32
418
        UA_NodeId_init(&id);
33
418
        UA_NodeId_parse(&id, str);
34
418
        UA_NodeId_clear(&id);
35
418
        break;
36
0
    }
37
1.42k
    case 1: {
38
1.42k
        UA_DateTime dt;
39
1.42k
        UA_DateTime_parse(&dt, str);
40
1.42k
        break;
41
0
    }
42
267
    case 2: {
43
267
        UA_Guid guid;
44
267
        UA_Guid_init(&guid);
45
267
        UA_Guid_parse(&guid, str);
46
267
        break;
47
0
    }
48
874
    case 3: {
49
874
        UA_ExpandedNodeId enid;
50
874
        UA_ExpandedNodeId_init(&enid);
51
874
        UA_ExpandedNodeId_parse(&enid, str);
52
874
        UA_ExpandedNodeId_clear(&enid);
53
874
        break;
54
0
    }
55
278
    case 4: {
56
278
        UA_QualifiedName qn;
57
278
        UA_QualifiedName_init(&qn);
58
278
        UA_QualifiedName_parse(&qn, str);
59
278
        UA_QualifiedName_clear(&qn);
60
278
        break;
61
0
    }
62
1.20k
    case 5: {
63
1.20k
        UA_RelativePath rp;
64
1.20k
        UA_RelativePath_init(&rp);
65
1.20k
        UA_StatusCode ret = UA_RelativePath_parse(&rp, str);
66
1.20k
        if(ret == UA_STATUSCODE_GOOD) {
67
755
            UA_String printed = UA_STRING_NULL;
68
755
            UA_RelativePath_print(&rp, &printed);
69
755
            UA_String_clear(&printed);
70
755
        }
71
1.20k
        UA_RelativePath_clear(&rp);
72
1.20k
        break;
73
0
    }
74
712
    case 6: {
75
712
        UA_SimpleAttributeOperand sao;
76
712
        UA_SimpleAttributeOperand_init(&sao);
77
712
        UA_SimpleAttributeOperand_parse(&sao, str);
78
712
        UA_SimpleAttributeOperand_clear(&sao);
79
712
        break;
80
0
    }
81
641
    case 7: {
82
641
        UA_ReadValueId rvi;
83
641
        UA_ReadValueId_init(&rvi);
84
641
        UA_ReadValueId_parse(&rvi, str);
85
641
        UA_ReadValueId_clear(&rvi);
86
641
        break;
87
0
    }
88
0
    default: break;
89
5.81k
    }
90
91
5.81k
    UA_String_clear(&str);
92
5.81k
    return 0;
93
5.81k
}