Coverage Report

Created: 2026-09-14 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/MapServer/fuzzers/mapfuzzer.c
Line
Count
Source
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
2.92k
#define kMinInputLength 10
21
1.45k
#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
7
int LLVMFuzzerInitialize(int *argc, char ***argv) {
27
7
  (void)argc;
28
7
  (void)argv;
29
7
  return 0;
30
7
}
31
32
1.46k
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
33
34
1.46k
  if (Size < kMinInputLength || Size > kMaxInputLength) {
35
18
    return 1;
36
18
  }
37
38
  // .map extension is required otherwise default pattern validation of
39
  // msLoadMap() would reject it
40
1.44k
  char *filename =
41
1.44k
      msStrdup(CPLSPrintf("%s.map", CPLGenerateTempFilename(NULL)));
42
1.44k
  FILE *fp = fopen(filename, "wb");
43
1.44k
  if (!fp) {
44
29
    msFree(filename);
45
29
    return 1;
46
29
  }
47
1.41k
  fwrite(Data, Size, 1, fp);
48
1.41k
  fclose(fp);
49
50
1.41k
  msFreeMap(msLoadMap(filename, NULL, NULL));
51
1.41k
  VSIUnlink(filename);
52
1.41k
  msFree(filename);
53
1.41k
  msResetErrorList();
54
55
1.41k
  return 0;
56
1.44k
}