/src/open62541/tests/fuzz/fuzz_attributeoperand.cc
Line | Count | Source (jump to first uncovered line) |
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 | 0 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
19 | 0 | if(size <= 6) |
20 | 0 | return 0; |
21 | | |
22 | | // set the available memory |
23 | 0 | if(!UA_memoryManager_setLimitFromLast4Bytes(data, size)) |
24 | 0 | return 0; |
25 | | |
26 | 0 | data += 4; |
27 | 0 | size -= 4; |
28 | |
|
29 | 0 | const UA_String input = {size, (UA_Byte *) (void *) data}; |
30 | 0 | UA_String out = UA_STRING_NULL; |
31 | 0 | UA_String out2 = UA_STRING_NULL; |
32 | |
|
33 | 0 | UA_AttributeOperand ao; |
34 | 0 | UA_AttributeOperand ao2; |
35 | 0 | UA_AttributeOperand_init(&ao2); |
36 | 0 | UA_StatusCode ret = UA_AttributeOperand_parse(&ao, input); |
37 | 0 | if(ret != UA_STATUSCODE_GOOD) |
38 | 0 | return 0; |
39 | | |
40 | 0 | ret = UA_AttributeOperand_print(&ao, &out); |
41 | 0 | if(ret == UA_STATUSCODE_BADOUTOFMEMORY) |
42 | 0 | goto cleanup; |
43 | 0 | UA_assert(ret == UA_STATUSCODE_GOOD); |
44 | | |
45 | 0 | ret = UA_AttributeOperand_parse(&ao2, out); |
46 | 0 | if(ret == UA_STATUSCODE_BADOUTOFMEMORY) |
47 | 0 | goto cleanup; |
48 | 0 | UA_assert(ret == UA_STATUSCODE_GOOD); |
49 | | |
50 | 0 | ret = UA_AttributeOperand_print(&ao2, &out2); |
51 | 0 | if(ret == UA_STATUSCODE_BADOUTOFMEMORY) |
52 | 0 | goto cleanup; |
53 | 0 | UA_assert(ret == UA_STATUSCODE_GOOD); |
54 | | |
55 | 0 | UA_assert(UA_String_equal(&out, &out2)); |
56 | 0 | UA_assert(UA_equal(&ao, &ao2, &UA_TYPES[UA_TYPES_ATTRIBUTEOPERAND])); |
57 | | |
58 | 0 | cleanup: |
59 | 0 | UA_String_clear(&out); |
60 | 0 | UA_String_clear(&out2); |
61 | 0 | UA_AttributeOperand_clear(&ao); |
62 | 0 | UA_AttributeOperand_clear(&ao2); |
63 | 0 | return 0; |
64 | 0 | } |