/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  | 38.9k  | #define kMinInputLength 10  | 
21  | 19.4k  | #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  | 6  | int LLVMFuzzerInitialize(int *argc, char ***argv) { | 
27  | 6  |   (void)argc;  | 
28  | 6  |   (void)argv;  | 
29  | 6  |   return 0;  | 
30  | 6  | }  | 
31  |  |  | 
32  | 19.4k  | extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | 
33  |  |  | 
34  | 19.4k  |   if (Size < kMinInputLength || Size > kMaxInputLength) { | 
35  | 34  |     return 1;  | 
36  | 34  |   }  | 
37  |  |  | 
38  | 19.4k  |   char *filename =  | 
39  | 19.4k  |       msStrdup(CPLSPrintf("%s.config", CPLGenerateTempFilename(NULL))); | 
40  | 19.4k  |   FILE *fp = fopen(filename, "wb");  | 
41  | 19.4k  |   if (!fp) { | 
42  | 0  |     msFree(filename);  | 
43  | 0  |     return 1;  | 
44  | 0  |   }  | 
45  | 19.4k  |   fwrite(Data, Size, 1, fp);  | 
46  | 19.4k  |   fclose(fp);  | 
47  |  |  | 
48  | 19.4k  |   msFreeConfig(msLoadConfig(filename));  | 
49  | 19.4k  |   VSIUnlink(filename);  | 
50  | 19.4k  |   msFree(filename);  | 
51  | 19.4k  |   msResetErrorList();  | 
52  |  |  | 
53  | 19.4k  |   return 0;  | 
54  | 19.4k  | }  |