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