/src/open62541_15/tests/fuzz/fuzz_mdns_message.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 | | } |
17 | | |
18 | | unsigned char message_buf[MAX_PACKET_LEN]; |
19 | | |
20 | | /* |
21 | | ** Main entry point. The fuzzer invokes this function with each |
22 | | ** fuzzed input. |
23 | | */ |
24 | | extern "C" int |
25 | 1.22k | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
26 | 1.22k | if(size >= MAX_PACKET_LEN) |
27 | 5 | return 0; |
28 | 1.21k | memcpy(message_buf, data, size); |
29 | 1.21k | message_buf[size] = 0; /* zero terminate */ |
30 | | |
31 | 1.21k | struct message m; |
32 | 1.21k | memset(&m, 0, sizeof(struct message)); |
33 | | |
34 | 1.21k | int parseResult = message_parse(&m, message_buf); |
35 | 1.21k | if(!parseResult) |
36 | 816 | return 0; |
37 | | |
38 | 401 | mdns_daemon_t *d = mdnsd_new(QCLASS_IN, 1000); |
39 | | |
40 | 401 | struct in_addr addr = {}; |
41 | 401 | mdnsd_in(d, &m, addr, 2000); |
42 | 401 | mdnsd_free(d); |
43 | | |
44 | 401 | return 0; |
45 | 1.21k | } |