/src/sleuthkit/ossfuzz/mmls_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 | | |
18 | | #include <memory> |
19 | | |
20 | | #include "tsk/tsk_tools_i.h" |
21 | | #include "mem_img.h" |
22 | | |
23 | | #ifndef VSTYPE |
24 | | #error Define VSTYPE as a valid value of TSK_VS_TYPE_ENUM. |
25 | | #endif |
26 | | |
27 | | static TSK_WALK_RET_ENUM part_act(TSK_VS_INFO *vs, const TSK_VS_PART_INFO *part, |
28 | 23.4k | void *ptr) { |
29 | 23.4k | return TSK_WALK_CONT; |
30 | 23.4k | } |
31 | | |
32 | 560 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
33 | 560 | TSK_VS_INFO *img = (TSK_VS_INFO*)mem_open(data, size); |
34 | 560 | if (!img) { |
35 | 0 | return 0; |
36 | 0 | } |
37 | | |
38 | 560 | std::unique_ptr<TSK_VS_INFO, decltype(&tsk_vs_close)> vs{ |
39 | 560 | tsk_vs_open((TSK_IMG_INFO *)img, 0, VSTYPE), |
40 | 560 | tsk_vs_close |
41 | 560 | }; |
42 | | |
43 | 560 | if (vs) { |
44 | 204 | tsk_vs_part_walk(vs.get(), 0, vs->part_count - 1, TSK_VS_PART_FLAG_ALL, part_act, |
45 | 204 | nullptr); |
46 | 204 | } |
47 | 560 | tsk_img_close((TSK_IMG_INFO*)img); |
48 | 560 | return 0; |
49 | 560 | } |