Coverage Report

Created: 2025-06-22 06:59

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