]>
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
;
25 if (size
> DNS_PACKET_SIZE_MAX
)
28 assert_se(dns_packet_new(&p
, DNS_PROTOCOL_DNS
, 0, DNS_PACKET_SIZE_MAX
) >= 0);
29 p
->size
= 0; /* by default append starts after the header, undo that */
30 assert_se(dns_packet_append_blob(p
, data
, size
, NULL
) >= 0);
31 if (size
< DNS_PACKET_HEADER_SIZE
) {
32 /* make sure we pad the packet back up to the minimum header size */
33 assert_se(p
->allocated
>= DNS_PACKET_HEADER_SIZE
);
34 memzero(DNS_PACKET_DATA(p
) + size
, DNS_PACKET_HEADER_SIZE
- size
);
35 p
->size
= DNS_PACKET_HEADER_SIZE
;
37 (void) dns_packet_extract(p
);