1 /* $NetBSD: isc_lex_gettoken.c,v 1.4 2026/01/29 18:37:48 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/lex.h> 21 #include <isc/mem.h> 22 #include <isc/util.h> 23 24 #include "fuzz.h" 25 26 bool debug = false; 27 28 static isc_mem_t *mctx = NULL; 29 static isc_lex_t *lex = NULL; 30 31 int 32 LLVMFuzzerInitialize(int *argc ISC_ATTR_UNUSED, char ***argv ISC_ATTR_UNUSED) { 33 isc_mem_create(&mctx); 34 isc_lex_create(mctx, 1024, &lex); 35 36 return 0; 37 } 38 39 int 40 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 41 isc_buffer_t buf; 42 isc_result_t result; 43 44 isc_buffer_constinit(&buf, data, size); 45 isc_buffer_add(&buf, size); 46 isc_buffer_setactive(&buf, size); 47 48 CHECK(isc_lex_openbuffer(lex, &buf)); 49 50 do { 51 isc_token_t token; 52 result = isc_lex_gettoken(lex, 0, &token); 53 } while (result == ISC_R_SUCCESS); 54 55 cleanup: 56 return 0; 57 } 58