+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 1 | /* |
| 2 | * SPDX-License-Identifier: AGPL-3.0-or-later WITH Classpath-exception-2.0 |
| 3 | * Copyright (c) 2026 Saif Mukhtar |
| 4 | * |
| 5 | * OpenAVX - Open Audio-Video eXchange |
| 6 | * fuzz/fuzz_discovery_udp.c - libFuzzer Target for Discovery Wire & DNS-SD Parsing |
| 7 | */ |
| 8 | |
| 9 | #include <stdint.h> |
| 10 | #include <stddef.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include "avx_wire.h" |
| 14 | |
| 15 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 16 | if (!data || size == 0) return 0; |
| 17 | |
| 18 | /* 1. Fuzz DNS label encoder and service scanner */ |
| 19 | char *str_input = (char *)malloc(size + 1); |
| 20 | if (str_input) { |
| 21 | memcpy(str_input, data, size); |
| 22 | str_input[size] = '\0'; |
| 23 | |
| 24 | uint8_t encoded[256]; |
| 25 | size_t enc_len = avx_wire_encode_dns_service(str_input, encoded, sizeof(encoded)); |
| 26 | |
| 27 | /* Exercise bounded output capacities */ |
| 28 | uint8_t small_encoded[32]; |
| 29 | size_t small_cap = (size_t)data[0] % sizeof(small_encoded); |
| 30 | (void)avx_wire_encode_dns_service(str_input, small_encoded, small_cap); |
| 31 | |
| 32 | size_t match_offset = 0; |
| 33 | (void)avx_wire_match_service(data, size, str_input, &match_offset); |
| 34 | (void)avx_wire_match_service(data, size, OAVX_WIRE_MDNS_SERVICE, &match_offset); |
| 35 | if (enc_len > 0) { |
| 36 | (void)avx_wire_match_service(encoded, enc_len, str_input, &match_offset); |
| 37 | } |
| 38 | |
| 39 | free(str_input); |
| 40 | } |
| 41 | |
| 42 | return 0; |
| 43 | } |