/src/open62541_15/tests/fuzz/fuzz_mdns_xht.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 2019 (c) fortiss (Author: Stefan Profanter) |
6 | | */ |
7 | | |
8 | | #include <cstdint> |
9 | | #include <cstdio> |
10 | | #include <cstring> |
11 | | #include <cstdlib> |
12 | | #include <open62541/config.h> |
13 | | |
14 | | extern "C" { |
15 | | #include "mdnsd.h" |
16 | | #include "xht.h" |
17 | | #include "sdtxt.h" |
18 | | } |
19 | | |
20 | | unsigned char message_buf[MAX_PACKET_LEN]; |
21 | | |
22 | | /* |
23 | | ** Main entry point. The fuzzer invokes this function with each |
24 | | ** fuzzed input. |
25 | | */ |
26 | | extern "C" int |
27 | 702 | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
28 | 702 | if(size >= MAX_PACKET_LEN) |
29 | 6 | return 0; |
30 | 696 | memcpy(message_buf, data, size); |
31 | 696 | message_buf[size] = 0; /* zero terminate */ |
32 | | |
33 | 696 | xht_t *sd = txt2sd(message_buf, size); |
34 | 696 | if(!sd) |
35 | 2 | return 0; |
36 | | |
37 | 694 | int len; |
38 | 694 | unsigned char *out = sd2txt(sd, &len); |
39 | 694 | assert(out != NULL); |
40 | | |
41 | 694 | free(out); |
42 | 694 | xht_free(sd); |
43 | | |
44 | 694 | return 0; |
45 | 694 | } |