xref: /netbsd-src/external/mpl/bind/dist/fuzz/dns_name_fromtext_target.c (revision 782713e6c126f1866c6d9cfdee4ceb49483b5828)
1 /*	$NetBSD: dns_name_fromtext_target.c,v 1.5 2022/09/23 12:15:29 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * SPDX-License-Identifier: MPL-2.0
7  *
8  * This Source Code Form is subject to the terms of the Mozilla Public
9  * License, v. 2.0. If a copy of the MPL was not distributed with this
10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11  *
12  * See the COPYRIGHT file distributed with this work for additional
13  * information regarding copyright ownership.
14  */
15 
16 #include <stddef.h>
17 #include <stdint.h>
18 
19 #include <isc/buffer.h>
20 #include <isc/util.h>
21 
22 #include <dns/fixedname.h>
23 #include <dns/name.h>
24 
25 int
26 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
27 
28 int
29 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
30 	isc_buffer_t buf;
31 	isc_result_t result;
32 	dns_fixedname_t origin;
33 	char *de_const;
34 
35 	if (size < 5) {
36 		return (0);
37 	}
38 
39 	dns_fixedname_init(&origin);
40 	DE_CONST(data, de_const);
41 	isc_buffer_init(&buf, (void *)de_const, size);
42 	isc_buffer_add(&buf, size);
43 	result = dns_name_fromtext(dns_fixedname_name(&origin), &buf,
44 				   dns_rootname, 0, NULL);
45 	UNUSED(result);
46 	return (0);
47 }
48