Coverage Report

Created: 2026-06-13 06:38

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