Line | Count | Source (jump to first uncovered line) |
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 | | #ifndef MEM_IMG_H |
16 | | #define MEM_IMG_H |
17 | | |
18 | | #include <stddef.h> |
19 | | #include <stdint.h> |
20 | | |
21 | | #include "sleuthkit/tsk/tsk_tools_i.h" |
22 | | |
23 | | typedef struct { |
24 | | TSK_IMG_INFO img_info; |
25 | | const uint8_t *data; |
26 | | size_t size; |
27 | | } IMG_MEM_INFO; |
28 | | |
29 | | static ssize_t mem_read(TSK_IMG_INFO *img_info, TSK_OFF_T offset, char *buf, |
30 | 813 | size_t len) { |
31 | 813 | IMG_MEM_INFO *mem_info = reinterpret_cast<IMG_MEM_INFO *>(img_info); |
32 | | // Bounds-checking exists in the real drivers. |
33 | 813 | if (offset > mem_info->size) { |
34 | 0 | return -1; |
35 | 0 | } |
36 | 813 | ssize_t read_len = len; |
37 | 813 | if (offset + len > mem_info->size) { |
38 | 0 | read_len = mem_info->size - offset; |
39 | 0 | } |
40 | 813 | if (memcpy(buf, mem_info->data + offset, read_len) == nullptr) { |
41 | 0 | return -1; |
42 | 813 | } else { |
43 | 813 | return read_len; |
44 | 813 | } |
45 | 813 | } sleuthkit_fls_apfs_fuzzer.cc:mem_read(TSK_IMG_INFO*, long, char*, unsigned long) Line | Count | Source | 30 | 1 | size_t len) { | 31 | 1 | IMG_MEM_INFO *mem_info = reinterpret_cast<IMG_MEM_INFO *>(img_info); | 32 | | // Bounds-checking exists in the real drivers. | 33 | 1 | if (offset > mem_info->size) { | 34 | 0 | return -1; | 35 | 0 | } | 36 | 1 | ssize_t read_len = len; | 37 | 1 | if (offset + len > mem_info->size) { | 38 | 0 | read_len = mem_info->size - offset; | 39 | 0 | } | 40 | 1 | if (memcpy(buf, mem_info->data + offset, read_len) == nullptr) { | 41 | 0 | return -1; | 42 | 1 | } else { | 43 | 1 | return read_len; | 44 | 1 | } | 45 | 1 | } |
sleuthkit_fls_fuzzer.cc:mem_read(TSK_IMG_INFO*, long, char*, unsigned long) Line | Count | Source | 30 | 235 | size_t len) { | 31 | 235 | IMG_MEM_INFO *mem_info = reinterpret_cast<IMG_MEM_INFO *>(img_info); | 32 | | // Bounds-checking exists in the real drivers. | 33 | 235 | if (offset > mem_info->size) { | 34 | 0 | return -1; | 35 | 0 | } | 36 | 235 | ssize_t read_len = len; | 37 | 235 | if (offset + len > mem_info->size) { | 38 | 0 | read_len = mem_info->size - offset; | 39 | 0 | } | 40 | 235 | if (memcpy(buf, mem_info->data + offset, read_len) == nullptr) { | 41 | 0 | return -1; | 42 | 235 | } else { | 43 | 235 | return read_len; | 44 | 235 | } | 45 | 235 | } |
sleuthkit_mmls_fuzzer.cc:mem_read(TSK_IMG_INFO*, long, char*, unsigned long) Line | Count | Source | 30 | 577 | size_t len) { | 31 | 577 | IMG_MEM_INFO *mem_info = reinterpret_cast<IMG_MEM_INFO *>(img_info); | 32 | | // Bounds-checking exists in the real drivers. | 33 | 577 | if (offset > mem_info->size) { | 34 | 0 | return -1; | 35 | 0 | } | 36 | 577 | ssize_t read_len = len; | 37 | 577 | if (offset + len > mem_info->size) { | 38 | 0 | read_len = mem_info->size - offset; | 39 | 0 | } | 40 | 577 | if (memcpy(buf, mem_info->data + offset, read_len) == nullptr) { | 41 | 0 | return -1; | 42 | 577 | } else { | 43 | 577 | return read_len; | 44 | 577 | } | 45 | 577 | } |
|
46 | | |
47 | 5.74k | static void mem_close(TSK_IMG_INFO *img_info) { |
48 | 5.74k | IMG_MEM_INFO *mem_info = reinterpret_cast<IMG_MEM_INFO *>(img_info); |
49 | 5.74k | tsk_deinit_lock(&(img_info->cache_lock)); |
50 | 5.74k | free(mem_info); |
51 | 5.74k | } sleuthkit_fls_apfs_fuzzer.cc:mem_close(TSK_IMG_INFO*) Line | Count | Source | 47 | 1 | static void mem_close(TSK_IMG_INFO *img_info) { | 48 | 1 | IMG_MEM_INFO *mem_info = reinterpret_cast<IMG_MEM_INFO *>(img_info); | 49 | 1 | tsk_deinit_lock(&(img_info->cache_lock)); | 50 | 1 | free(mem_info); | 51 | 1 | } |
sleuthkit_fls_fuzzer.cc:mem_close(TSK_IMG_INFO*) Line | Count | Source | 47 | 3.42k | static void mem_close(TSK_IMG_INFO *img_info) { | 48 | 3.42k | IMG_MEM_INFO *mem_info = reinterpret_cast<IMG_MEM_INFO *>(img_info); | 49 | 3.42k | tsk_deinit_lock(&(img_info->cache_lock)); | 50 | 3.42k | free(mem_info); | 51 | 3.42k | } |
sleuthkit_mmls_fuzzer.cc:mem_close(TSK_IMG_INFO*) Line | Count | Source | 47 | 2.32k | static void mem_close(TSK_IMG_INFO *img_info) { | 48 | 2.32k | IMG_MEM_INFO *mem_info = reinterpret_cast<IMG_MEM_INFO *>(img_info); | 49 | 2.32k | tsk_deinit_lock(&(img_info->cache_lock)); | 50 | 2.32k | free(mem_info); | 51 | 2.32k | } |
|
52 | | |
53 | 0 | static void mem_imgstat(TSK_IMG_INFO *img_info, FILE *hFile) {} Unexecuted instantiation: sleuthkit_fls_apfs_fuzzer.cc:mem_imgstat(TSK_IMG_INFO*, _IO_FILE*) Unexecuted instantiation: sleuthkit_fls_fuzzer.cc:mem_imgstat(TSK_IMG_INFO*, _IO_FILE*) Unexecuted instantiation: sleuthkit_mmls_fuzzer.cc:mem_imgstat(TSK_IMG_INFO*, _IO_FILE*) |
54 | | |
55 | 5.74k | TSK_IMG_INFO *mem_open(const uint8_t *data, size_t size) { |
56 | 5.74k | IMG_MEM_INFO *inmemory_img = |
57 | 5.74k | reinterpret_cast<IMG_MEM_INFO *>(malloc(sizeof(IMG_MEM_INFO))); |
58 | 5.74k | TSK_IMG_INFO *img; |
59 | 5.74k | if (inmemory_img == nullptr) { |
60 | 0 | return nullptr; |
61 | 0 | } |
62 | 5.74k | img = reinterpret_cast<TSK_IMG_INFO *>(inmemory_img); |
63 | 5.74k | img->itype = TSK_IMG_TYPE_RAW; |
64 | 5.74k | img->read = mem_read; |
65 | 5.74k | img->close = mem_close; |
66 | 5.74k | img->imgstat = mem_imgstat; |
67 | 5.74k | img->size = size; |
68 | 5.74k | img->sector_size = 512; |
69 | 5.74k | tsk_init_lock(&(img->cache_lock)); |
70 | 5.74k | inmemory_img->data = data; |
71 | 5.74k | inmemory_img->size = size; |
72 | 5.74k | return img; |
73 | 5.74k | } |
74 | | |
75 | | #endif // # MEM_IMG_H |