/src/MapServer/fuzzers/configfuzzer.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2022 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include <stdint.h> |
14 | | #include <string.h> |
15 | | |
16 | | #include "cpl_conv.h" |
17 | | #include "cpl_string.h" |
18 | | #include "src/mapserver.h" |
19 | | |
20 | 6.34k | #define kMinInputLength 10 |
21 | 3.16k | #define kMaxInputLength 10240 |
22 | | |
23 | | extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size); |
24 | | extern int LLVMFuzzerInitialize(int *argc, char ***argv); |
25 | | |
26 | 2 | int LLVMFuzzerInitialize(int *argc, char ***argv) { |
27 | 2 | (void)argc; |
28 | 2 | (void)argv; |
29 | 2 | return 0; |
30 | 2 | } |
31 | | |
32 | 3.17k | extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
33 | | |
34 | 3.17k | if (Size < kMinInputLength || Size > kMaxInputLength) { |
35 | 20 | return 1; |
36 | 20 | } |
37 | | |
38 | 3.15k | char *filename = |
39 | 3.15k | msStrdup(CPLSPrintf("%s.config", CPLGenerateTempFilename(NULL))); |
40 | 3.15k | FILE *fp = fopen(filename, "wb"); |
41 | 3.15k | if (!fp) { |
42 | 0 | msFree(filename); |
43 | 0 | return 1; |
44 | 0 | } |
45 | 3.15k | fwrite(Data, Size, 1, fp); |
46 | 3.15k | fclose(fp); |
47 | | |
48 | 3.15k | msFreeConfig(msLoadConfig(filename)); |
49 | 3.15k | VSIUnlink(filename); |
50 | 3.15k | msFree(filename); |
51 | 3.15k | msResetErrorList(); |
52 | | |
53 | 3.15k | return 0; |
54 | 3.15k | } |