2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-24 19:18:50 +00:00
bind/fuzz/dns_name_fromtext_target.c
Petr Špaček dc9ba2d3ef
Add dns_rdata_fromtext() fuzzer
... along with dns_rdataclass_fromtext and dns_rdatatype_fromtext

Most of the test binary is modified named-rrchecker. Main differences:
- reads single RR and exists
- does not refuse meta classes and rr types
We actually do have some fromtext code for meta-things so erroring out
in named-rrchecker would prevent us from testing this code.

Corpus has examples of all currently supported RR types. I did not do
any minimization.

In future use command

    diff -U0 \
	<(sed -n -e 's/^.*fromtext_\(.*\)(.*$/\1/p' lib/dns/code.h | \
		sort) \
	<(ls fuzz/dns_rdata_fromtext.in/)

to check for missing RR types.
2022-02-24 11:12:06 +01:00

53 lines
1.2 KiB
C

/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#include <stddef.h>
#include <stdint.h>
#include <isc/buffer.h>
#include <isc/util.h>
#include <dns/fixedname.h>
#include <dns/name.h>
#include "fuzz.h"
bool debug = false;
int
LLVMFuzzerInitialize(int *argc __attribute__((unused)),
char ***argv __attribute__((unused))) {
return (0);
}
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
isc_buffer_t buf;
isc_result_t result;
dns_fixedname_t origin;
dns_fixedname_init(&origin);
isc_buffer_constinit(&buf, data, size);
isc_buffer_add(&buf, size);
isc_buffer_setactive(&buf, size);
result = dns_name_fromtext(dns_fixedname_name(&origin), &buf,
dns_rootname, 0, NULL);
if (debug) {
fprintf(stderr, "dns_name_fromtext: %s\n",
isc_result_totext(result));
}
return (0);
}