/src/lldpd/tests/fuzz_lldp.c
Line | Count | Source |
1 | | /* -*- mode: c; c-file-style: "openbsd" -*- */ |
2 | | /* |
3 | | * Copyright (c) 2023 Vincent Bernat <bernat@luffy.cx> |
4 | | * |
5 | | * Permission to use, copy, modify, and/or distribute this software for any |
6 | | * purpose with or without fee is hereby granted, provided that the above |
7 | | * copyright notice and this permission notice appear in all copies. |
8 | | * |
9 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
10 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
11 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
12 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
13 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
14 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
15 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | | */ |
17 | | |
18 | | #include "../src/daemon/lldpd.h" |
19 | | |
20 | 2.69k | #define kMinInputLength 5 |
21 | 1.33k | #define kMaxInputLength 2048 |
22 | | |
23 | | /* Use this callback to avoid some logs */ |
24 | 20.5k | void donothing(int pri, const char *msg) {}; |
25 | | |
26 | | extern int |
27 | | LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
28 | 1.34k | { |
29 | 1.34k | if (Size < kMinInputLength || Size > kMaxInputLength) { |
30 | 52 | return 1; |
31 | 52 | } |
32 | | |
33 | 1.29k | struct lldpd_chassis *nchassis = NULL; |
34 | 1.29k | struct lldpd_port *nport = NULL; |
35 | 1.29k | struct lldpd_hardware hardware; |
36 | | |
37 | 1.29k | log_register(donothing); |
38 | | |
39 | 1.29k | lldp_decode(NULL, (char *)Data, Size, &hardware, &nchassis, &nport); |
40 | | |
41 | 1.29k | if (!nchassis || !nport) { |
42 | 1.05k | return 1; |
43 | 1.05k | } |
44 | | |
45 | 238 | lldpd_port_cleanup(nport, 1); |
46 | 238 | free(nport); |
47 | 238 | lldpd_chassis_cleanup(nchassis, 1); |
48 | | |
49 | 238 | return 0; |
50 | 1.29k | } |