/src/haproxy/fuzz_cfg_parser.c
Line | Count | Source |
1 | | /* |
2 | | # Copyright 2020 Google Inc. |
3 | | # |
4 | | # Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | # you may not use this file except in compliance with the License. |
6 | | # You may obtain a copy of the License at |
7 | | # |
8 | | # http://www.apache.org/licenses/LICENSE-2.0 |
9 | | # |
10 | | # Unless required by applicable law or agreed to in writing, software |
11 | | # distributed under the License is distributed on an "AS IS" BASIS, |
12 | | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | # See the License for the specific language governing permissions and |
14 | | # limitations under the License. |
15 | | # |
16 | | ################################################################################ |
17 | | */ |
18 | | |
19 | | #include <haproxy/cfgparse.h> |
20 | | #include <haproxy/chunk.h> |
21 | | #include <haproxy/global.h> |
22 | | |
23 | | #include <stdint.h> |
24 | | #include <stdio.h> |
25 | | #include <stdlib.h> |
26 | | #include <unistd.h> |
27 | | |
28 | 2 | #define FUZZ_TRASH_SIZE 65536 |
29 | | |
30 | | static int trash_initialized = 0; |
31 | | |
32 | 4.15k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
33 | | /* One-time init: use init_trash_buffers() to properly initialize all trash |
34 | | * buffers (trash, trash_buf1, trash_buf2 and their large/small variants). |
35 | | * This mirrors haproxy's alloc_early_trash + alloc_trash_buffers_per_thread |
36 | | * startup sequence. */ |
37 | 4.15k | if (!trash_initialized) { |
38 | 1 | global.tune.bufsize = FUZZ_TRASH_SIZE; |
39 | 1 | global.tune.bufsize_large = FUZZ_TRASH_SIZE * 2; |
40 | 1 | global.tune.bufsize_small = 1024; |
41 | 1 | if (!init_trash_buffers(1)) |
42 | 0 | return 0; |
43 | 1 | if (!init_trash_buffers(0)) |
44 | 0 | return 0; |
45 | 1 | trash_initialized = 1; |
46 | 1 | } |
47 | | |
48 | 4.15k | struct cfgfile dummy_cfg = { |
49 | 4.15k | .filename = "fuzzer", |
50 | 4.15k | .content = (const char *)data, |
51 | 4.15k | .size = size, |
52 | 4.15k | }; |
53 | 4.15k | if (size < 50) |
54 | 12 | return 0; |
55 | | |
56 | 4.14k | parse_cfg(&dummy_cfg); |
57 | 4.14k | return 0; |
58 | 4.15k | } |