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