Coverage Report

Created: 2026-03-18 06:51

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
57
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
26
27
57
  enum FuzzerType {
28
57
    ext2fsReadBlockBitmap,
29
57
    ext2fsReadInodeBitmap,
30
57
    kMaxValue = ext2fsReadInodeBitmap
31
57
  };
32
33
57
  FuzzedDataProvider stream(data, size);
34
57
  const FuzzerType f = stream.ConsumeEnum<FuzzerType>();
35
57
  (void) stream.ConsumeIntegral<int>();
36
37
57
  static const char* fname = "ext2_test_file";
38
39
  // Write our data to a temp file.
40
57
  int fd = syscall(SYS_memfd_create, fname, 0);
41
57
  std::vector<char> buffer = stream.ConsumeRemainingBytes<char>();
42
57
  write(fd, buffer.data(), buffer.size());
43
44
57
  std::string fspath("/proc/self/fd/" + std::to_string(fd));
45
46
57
  ext2_filsys fs;
47
57
  errcode_t retval = ext2fs_open(
48
57
      fspath.c_str(),
49
57
      EXT2_FLAG_IGNORE_CSUM_ERRORS, 0, 0,
50
57
      unix_io_manager,
51
57
      &fs);
52
53
57
  if (!retval) {
54
38
    switch (f) {
55
35
      case ext2fsReadBlockBitmap: {
56
35
        ext2fs_read_block_bitmap(fs);
57
35
        break;
58
0
      }
59
3
      case ext2fsReadInodeBitmap: {
60
3
        ext2fs_read_inode_bitmap(fs);
61
3
        break;
62
0
      }
63
0
      default: {
64
0
        assert(false);
65
0
      }
66
38
    }
67
38
    ext2fs_close(fs);
68
38
  }
69
57
  close(fd);
70
71
57
  return 0;
72
57
}