Home | History | Annotate | Line # | Download | only in fuzz
      1  1.1  christos /*	$NetBSD: isc_lex_gettoken.c,v 1.4 2026/01/29 18:37:48 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  1.1  christos  *
      6  1.1  christos  * SPDX-License-Identifier: MPL-2.0
      7  1.1  christos  *
      8  1.1  christos  * This Source Code Form is subject to the terms of the Mozilla Public
      9  1.1  christos  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10  1.1  christos  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11  1.1  christos  *
     12  1.1  christos  * See the COPYRIGHT file distributed with this work for additional
     13  1.1  christos  * information regarding copyright ownership.
     14  1.1  christos  */
     15  1.1  christos 
     16  1.1  christos #include <stddef.h>
     17  1.1  christos #include <stdint.h>
     18  1.1  christos 
     19  1.1  christos #include <isc/buffer.h>
     20  1.1  christos #include <isc/lex.h>
     21  1.1  christos #include <isc/mem.h>
     22  1.1  christos #include <isc/util.h>
     23  1.1  christos 
     24  1.1  christos #include "fuzz.h"
     25  1.1  christos 
     26  1.1  christos bool debug = false;
     27  1.1  christos 
     28  1.1  christos static isc_mem_t *mctx = NULL;
     29  1.1  christos static isc_lex_t *lex = NULL;
     30  1.1  christos 
     31  1.1  christos int
     32  1.3  christos LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) {
     33  1.1  christos 	isc_mem_create(&mctx);
     34  1.3  christos 	isc_lex_create(mctx, 1024, &lex);
     35  1.1  christos 
     36  1.3  christos 	return 0;
     37  1.1  christos }
     38  1.1  christos 
     39  1.1  christos int
     40  1.1  christos LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
     41  1.1  christos 	isc_buffer_t buf;
     42  1.1  christos 	isc_result_t result;
     43  1.1  christos 
     44  1.1  christos 	isc_buffer_constinit(&buf, data, size);
     45  1.1  christos 	isc_buffer_add(&buf, size);
     46  1.1  christos 	isc_buffer_setactive(&buf, size);
     47  1.1  christos 
     48  1.1  christos 	CHECK(isc_lex_openbuffer(lex, &buf));
     49  1.1  christos 
     50  1.1  christos 	do {
     51  1.1  christos 		isc_token_t token;
     52  1.1  christos 		result = isc_lex_gettoken(lex, 0, &token);
     53  1.1  christos 	} while (result == ISC_R_SUCCESS);
     54  1.1  christos 
     55  1.4  christos cleanup:
     56  1.3  christos 	return 0;
     57  1.1  christos }
     58