Coverage Report

Created: 2026-05-16 06:54

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.95k
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
15
5.95k
    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.94k
    uint8_t selector = data[0];
20
5.94k
    const uint8_t *payload = data + 1;
21
5.94k
    size_t payload_size = size - 1;
22
23
5.94k
    UA_String str;
24
5.94k
    UA_StatusCode retval = UA_ByteString_allocBuffer(&str, payload_size);
25
5.94k
    if(retval != UA_STATUSCODE_GOOD)
26
0
        return 0;
27
5.94k
    memcpy(str.data, payload, payload_size);
28
29
5.94k
    switch(selector % 8) {
30
419
    case 0: {
31
419
        UA_NodeId id;
32
419
        UA_NodeId_init(&id);
33
419
        UA_NodeId_parse(&id, str);
34
419
        UA_NodeId_clear(&id);
35
419
        break;
36
0
    }
37
1.51k
    case 1: {
38
1.51k
        UA_DateTime dt;
39
1.51k
        UA_DateTime_parse(&dt, str);
40
1.51k
        break;
41
0
    }
42
263
    case 2: {
43
263
        UA_Guid guid;
44
263
        UA_Guid_init(&guid);
45
263
        UA_Guid_parse(&guid, str);
46
263
        break;
47
0
    }
48
887
    case 3: {
49
887
        UA_ExpandedNodeId enid;
50
887
        UA_ExpandedNodeId_init(&enid);
51
887
        UA_ExpandedNodeId_parse(&enid, str);
52
887
        UA_ExpandedNodeId_clear(&enid);
53
887
        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.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
758
            UA_String printed = UA_STRING_NULL;
68
758
            UA_RelativePath_print(&rp, &printed);
69
758
            UA_String_clear(&printed);
70
758
        }
71
1.20k
        UA_RelativePath_clear(&rp);
72
1.20k
        break;
73
0
    }
74
707
    case 6: {
75
707
        UA_SimpleAttributeOperand sao;
76
707
        UA_SimpleAttributeOperand_init(&sao);
77
707
        UA_SimpleAttributeOperand_parse(&sao, str);
78
707
        UA_SimpleAttributeOperand_clear(&sao);
79
707
        break;
80
0
    }
81
693
    case 7: {
82
693
        UA_ReadValueId rvi;
83
693
        UA_ReadValueId_init(&rvi);
84
693
        UA_ReadValueId_parse(&rvi, str);
85
693
        UA_ReadValueId_clear(&rvi);
86
693
        break;
87
0
    }
88
0
    default: break;
89
5.94k
    }
90
91
5.94k
    UA_String_clear(&str);
92
5.94k
    return 0;
93
5.94k
}