1:255.13-alt1
[systemd_ALT.git] / src / resolve / fuzz-dns-packet.c
bloba5b1fd64f763cbca75ab4195919b74aadb9e5338
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 #include "fuzz.h"
4 #include "memory-util.h"
5 #include "resolved-dns-packet.h"
7 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
8 _cleanup_(dns_packet_unrefp) DnsPacket *p = NULL;
10 if (outside_size_range(size, 0, DNS_PACKET_SIZE_MAX))
11 return 0;
13 fuzz_setup_logging();
15 assert_se(dns_packet_new(&p, DNS_PROTOCOL_DNS, 0, DNS_PACKET_SIZE_MAX) >= 0);
16 p->size = 0; /* by default append starts after the header, undo that */
17 assert_se(dns_packet_append_blob(p, data, size, NULL) >= 0);
18 if (size < DNS_PACKET_HEADER_SIZE) {
19 /* make sure we pad the packet back up to the minimum header size */
20 assert_se(p->allocated >= DNS_PACKET_HEADER_SIZE);
21 memzero(DNS_PACKET_DATA(p) + size, DNS_PACKET_HEADER_SIZE - size);
22 p->size = DNS_PACKET_HEADER_SIZE;
24 (void) dns_packet_extract(p);
26 return 0;