]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/fuzz/fuzz-dns-packet.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2018 Jonathan Rudenberg
5 systemd is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 systemd is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "resolved-dns-packet.h"
22 int LLVMFuzzerTestOneInput(const uint8_t *data
, size_t size
) {
23 _cleanup_(dns_packet_unrefp
) DnsPacket
*p
= NULL
;
26 if (size
> DNS_PACKET_SIZE_MAX
)
29 r
= dns_packet_new(&p
, DNS_PROTOCOL_DNS
, 0, DNS_PACKET_SIZE_MAX
);
32 p
->size
= 0; /* by default append starts after the header, undo that */
33 dns_packet_append_blob(p
, data
, size
, NULL
);
34 if (size
< DNS_PACKET_HEADER_SIZE
) {
35 /* make sure we pad the packet back up to the minimum header size */
36 assert(p
->allocated
>= DNS_PACKET_HEADER_SIZE
);
37 memzero(DNS_PACKET_DATA(p
) + size
, DNS_PACKET_HEADER_SIZE
- size
);
38 p
->size
= DNS_PACKET_HEADER_SIZE
;
40 dns_packet_extract(p
);