/src/MapServer/fuzzers/mapfuzzer.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 | 32.6k | #define kMinInputLength 10 |
21 | 16.3k | #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 | 16.3k | extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
33 | | |
34 | 16.3k | if (Size < kMinInputLength || Size > kMaxInputLength) { |
35 | 14 | return 1; |
36 | 14 | } |
37 | | |
38 | | // .map extension is required otherwise default pattern validation of |
39 | | // msLoadMap() would reject it |
40 | 16.3k | char *filename = |
41 | 16.3k | msStrdup(CPLSPrintf("%s.map", CPLGenerateTempFilename(NULL))); |
42 | 16.3k | FILE *fp = fopen(filename, "wb"); |
43 | 16.3k | if (!fp) { |
44 | 0 | msFree(filename); |
45 | 0 | return 1; |
46 | 0 | } |
47 | 16.3k | fwrite(Data, Size, 1, fp); |
48 | 16.3k | fclose(fp); |
49 | | |
50 | 16.3k | msFreeMap(msLoadMap(filename, NULL, NULL)); |
51 | 16.3k | VSIUnlink(filename); |
52 | 16.3k | msFree(filename); |
53 | 16.3k | msResetErrorList(); |
54 | | |
55 | 16.3k | return 0; |
56 | 16.3k | } |