1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
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
))
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
);