Coverage Report

Created: 2024-04-23 06:05

/src/sleuthkit_fls_apfs_fuzzer.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2021 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
18
#include "sleuthkit/tsk/tsk_tools_i.h"
19
#include "sleuthkit/tsk/fs/tsk_fs.h"
20
#include "sleuthkit/tsk/pool/tsk_pool.h"
21
#include "sleuthkit_mem_img.h"
22
23
1
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
24
1
  TSK_IMG_INFO* img;
25
1
  TSK_IMG_INFO* pool_img;
26
1
  TSK_FS_INFO* fs;
27
1
  const TSK_POOL_INFO* pool;
28
29
1
  img = mem_open(data, size);
30
1
  if (img == nullptr) {
31
0
    return 0;
32
0
  }
33
1
  pool = tsk_pool_open_img_sing(img, 0, TSK_POOL_TYPE_APFS);
34
35
1
  if (pool == nullptr) {
36
1
    goto out_img;
37
1
  }
38
  // Pool start block is APFS container specific and is hard coded for now
39
0
  pool_img = pool->get_img_info(pool, (TSK_DADDR_T) 106);
40
41
0
  if (pool_img == nullptr) {
42
0
    goto out_pool;
43
0
  }
44
0
  fs = tsk_fs_open_img_decrypt(pool_img, 0, TSK_FS_TYPE_APFS_DETECT, "");
45
46
0
  if (fs != nullptr) {
47
0
    tsk_fs_fls(fs, TSK_FS_FLS_FULL, fs->root_inum, TSK_FS_DIR_WALK_FLAG_RECURSE, nullptr, 0);
48
49
0
    fs->close(fs);
50
0
  }
51
0
  tsk_img_close(pool_img);
52
53
0
out_pool:
54
0
  tsk_pool_close(pool);
55
56
1
out_img:
57
1
  tsk_img_close(img);
58
59
1
  return 0;
60
0
}