Coverage Report

Created: 2026-03-15 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fuzz/ext2fs_read_bitmap_fuzzer.cc
Line
Count
Source
1
// Copyright 2020 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
#include <stddef.h>
16
#include <stdint.h>
17
#include <unistd.h>
18
#include <assert.h>
19
#include <sys/syscall.h>
20
#include <linux/memfd.h>
21
#include <fuzzer/FuzzedDataProvider.h>
22
23
#include "ext2fs/ext2fs.h"
24
25
93
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
26
27
93
  enum FuzzerType {
28
93
    ext2fsReadBlockBitmap,
29
93
    ext2fsReadInodeBitmap,
30
93
    kMaxValue = ext2fsReadInodeBitmap
31
93
  };
32
33
93
  FuzzedDataProvider stream(data, size);
34
93
  const FuzzerType f = stream.ConsumeEnum<FuzzerType>();
35
93
  (void) stream.ConsumeIntegral<int>();
36
37
93
  static const char* fname = "ext2_test_file";
38
39
  // Write our data to a temp file.
40
93
  int fd = syscall(SYS_memfd_create, fname, 0);
41
93
  std::vector<char> buffer = stream.ConsumeRemainingBytes<char>();
42
93
  write(fd, buffer.data(), buffer.size());
43
44
93
  std::string fspath("/proc/self/fd/" + std::to_string(fd));
45
46
93
  ext2_filsys fs;
47
93
  errcode_t retval = ext2fs_open(
48
93
      fspath.c_str(),
49
93
      EXT2_FLAG_IGNORE_CSUM_ERRORS, 0, 0,
50
93
      unix_io_manager,
51
93
      &fs);
52
53
93
  if (!retval) {
54
65
    switch (f) {
55
56
      case ext2fsReadBlockBitmap: {
56
56
        ext2fs_read_block_bitmap(fs);
57
56
        break;
58
0
      }
59
9
      case ext2fsReadInodeBitmap: {
60
9
        ext2fs_read_inode_bitmap(fs);
61
9
        break;
62
0
      }
63
0
      default: {
64
0
        assert(false);
65
0
      }
66
65
    }
67
65
    ext2fs_close(fs);
68
65
  }
69
93
  close(fd);
70
71
93
  return 0;
72
93
}