Debian Codegraph @

fuzz/isc_lex_gettoken.c

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