Coverage Report

Created: 2025-08-26 06:29

/src/fuzz_libinfo.cpp
Line
Count
Source
1
// Copyright 2025 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
#include <stdint.h>
17
#include <stddef.h>
18
#include <vector>
19
#include <cstdlib>
20
#include <algorithm>
21
22
#include "microhttpd2.h"
23
#include "fuzzer/FuzzedDataProvider.h"
24
25
642
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
26
642
  FuzzedDataProvider fdp(data, size);
27
28
  // Generate random ids
29
642
  int fixed_id   = fdp.ConsumeIntegral<int>();
30
642
  int dynamic_id = fdp.ConsumeIntegral<int>();
31
32
  // Generate random raw data
33
642
  std::vector<uint8_t> raw_data = fdp.ConsumeRemainingBytes<uint8_t>();
34
35
  // Fuzz MHD_lib_get_info_fixed_sz
36
642
  MHD_lib_get_info_fixed_sz(
37
642
      static_cast<MHD_LibInfoFixed>(fixed_id),
38
642
      raw_data.size() > 0 ? reinterpret_cast<MHD_LibInfoFixedData*>(raw_data.data()) : nullptr,
39
642
      raw_data.size());
40
41
  // Fuzz MHD_lib_get_info_dynamic_sz
42
642
  MHD_lib_get_info_dynamic_sz(
43
642
      static_cast<MHD_LibInfoDynamic>(dynamic_id),
44
642
      raw_data.size() > 0 ? reinterpret_cast<MHD_LibInfoDynamicData*>(raw_data.data()) : nullptr,
45
642
      raw_data.size());
46
47
642
  return 0;
48
642
}