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_attributeoperand.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 2024 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
6
 */
7
8
#include "custom_memory_manager.h"
9
10
#include <open62541/plugin/log_stdout.h>
11
#include <open62541/server_config_default.h>
12
#include <open62541/types.h>
13
14
/*
15
** Main entry point.  The fuzzer invokes this function with each
16
** fuzzed input.
17
*/
18
2.25k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
19
2.25k
    if(size <= 6)
20
4
        return 0;
21
22
    // set the available memory
23
2.25k
    if(!UA_memoryManager_setLimitFromLast4Bytes(data, size))
24
0
        return 0;
25
26
2.25k
    data += 4;
27
2.25k
    size -= 4;
28
29
2.25k
    const UA_String input = {size, (UA_Byte *) (void *) data};
30
2.25k
    UA_String out = UA_STRING_NULL;
31
2.25k
    UA_String out2 = UA_STRING_NULL;
32
33
2.25k
    UA_AttributeOperand ao;
34
2.25k
    UA_AttributeOperand ao2;
35
2.25k
    UA_AttributeOperand_init(&ao2);
36
2.25k
    UA_StatusCode ret = UA_AttributeOperand_parse(&ao, input);
37
2.25k
    if(ret != UA_STATUSCODE_GOOD)
38
1.20k
        return 0;
39
40
1.04k
    ret = UA_AttributeOperand_print(&ao, &out);
41
1.04k
    if(ret == UA_STATUSCODE_BADOUTOFMEMORY)
42
0
        goto cleanup;
43
1.04k
    UA_assert(ret == UA_STATUSCODE_GOOD);
44
45
1.04k
    ret = UA_AttributeOperand_parse(&ao2, out);
46
1.04k
    if(ret == UA_STATUSCODE_BADOUTOFMEMORY)
47
0
        goto cleanup;
48
1.04k
    UA_assert(ret == UA_STATUSCODE_GOOD);
49
50
1.04k
    ret = UA_AttributeOperand_print(&ao2, &out2);
51
1.04k
    if(ret == UA_STATUSCODE_BADOUTOFMEMORY)
52
0
        goto cleanup;
53
1.04k
    UA_assert(ret == UA_STATUSCODE_GOOD);
54
55
1.04k
    UA_assert(UA_String_equal(&out, &out2));
56
1.04k
    UA_assert(UA_equal(&ao, &ao2, &UA_TYPES[UA_TYPES_ATTRIBUTEOPERAND]));
57
58
1.04k
 cleanup:
59
1.04k
    UA_String_clear(&out);
60
1.04k
    UA_String_clear(&out2);
61
1.04k
    UA_AttributeOperand_clear(&ao);
62
1.04k
    UA_AttributeOperand_clear(&ao2);
63
1.04k
    return 0;
64
1.04k
}