isc_lex_gettoken.c revision 1.1 1 /* $NetBSD: isc_lex_gettoken.c,v 1.1 2024/02/21 21:54:46 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 __attribute__((unused)),
33 char ***argv __attribute__((unused))) {
34 isc_result_t result;
35
36 isc_mem_create(&mctx);
37
38 result = isc_lex_create(mctx, 1024, &lex);
39 REQUIRE(result == ISC_R_SUCCESS);
40
41 return (0);
42 }
43
44 int
45 LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
46 isc_buffer_t buf;
47 isc_result_t result;
48
49 isc_buffer_constinit(&buf, data, size);
50 isc_buffer_add(&buf, size);
51 isc_buffer_setactive(&buf, size);
52
53 CHECK(isc_lex_openbuffer(lex, &buf));
54
55 do {
56 isc_token_t token;
57 result = isc_lex_gettoken(lex, 0, &token);
58 } while (result == ISC_R_SUCCESS);
59
60 return (0);
61 }
62