/src/libfsapfs/ossfuzz/file_entry_fuzzer.cc
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * OSS-Fuzz target for libfsapfs file_entry type |
3 | | * |
4 | | * Copyright (C) 2018-2024, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <stddef.h> |
23 | | #include <stdint.h> |
24 | | |
25 | | /* Note that some of the OSS-Fuzz engines use C++ |
26 | | */ |
27 | | extern "C" { |
28 | | |
29 | | #include "ossfuzz_libbfio.h" |
30 | | #include "ossfuzz_libfsapfs.h" |
31 | | |
32 | | #if !defined( LIBFSAPFS_HAVE_BFIO ) |
33 | | |
34 | | /* Opens a container using a Basic File IO (bfio) handle |
35 | | * Returns 1 if successful or -1 on error |
36 | | */ |
37 | | LIBFSAPFS_EXTERN \ |
38 | | int libfsapfs_container_open_file_io_handle( |
39 | | libfsapfs_container_t *container, |
40 | | libbfio_handle_t *file_io_handle, |
41 | | int access_flags, |
42 | | libfsapfs_error_t **error ); |
43 | | |
44 | | #endif /* !defined( LIBFSAPFS_HAVE_BFIO ) */ |
45 | | |
46 | | int LLVMFuzzerTestOneInput( |
47 | | const uint8_t *data, |
48 | | size_t size ) |
49 | 4.37k | { |
50 | 4.37k | uint8_t string_value[ 64 ]; |
51 | | |
52 | 4.37k | libbfio_handle_t *file_io_handle = NULL; |
53 | 4.37k | libfsapfs_container_t *container = NULL; |
54 | 4.37k | libfsapfs_file_entry_t *root_directory = NULL; |
55 | 4.37k | libfsapfs_file_entry_t *sub_file_entry = NULL; |
56 | 4.37k | libfsapfs_volume_t *volume = NULL; |
57 | 4.37k | size64_t file_size = 0; |
58 | 4.37k | size_t string_size = 0; |
59 | 4.37k | off64_t file_offset = 0; |
60 | 4.37k | uint64_t value_64bit = 0; |
61 | 4.37k | int64_t posix_time = 0; |
62 | 4.37k | uint32_t major_device_number = 0; |
63 | 4.37k | uint32_t minor_device_number = 0; |
64 | 4.37k | uint32_t value_32bit = 0; |
65 | 4.37k | uint16_t value_16bit = 0; |
66 | 4.37k | int number_of_extents = 0; |
67 | 4.37k | int number_of_sub_file_entries = 0; |
68 | 4.37k | int number_of_volumes = 0; |
69 | 4.37k | int result = 0; |
70 | | |
71 | 4.37k | if( libbfio_memory_range_initialize( |
72 | 4.37k | &file_io_handle, |
73 | 4.37k | NULL ) != 1 ) |
74 | 0 | { |
75 | 0 | return( 0 ); |
76 | 0 | } |
77 | 4.37k | if( libbfio_memory_range_set( |
78 | 4.37k | file_io_handle, |
79 | 4.37k | (uint8_t *) data, |
80 | 4.37k | size, |
81 | 4.37k | NULL ) != 1 ) |
82 | 0 | { |
83 | 0 | goto on_error_libbfio; |
84 | 0 | } |
85 | 4.37k | if( libfsapfs_container_initialize( |
86 | 4.37k | &container, |
87 | 4.37k | NULL ) != 1 ) |
88 | 0 | { |
89 | 0 | goto on_error_libbfio; |
90 | 0 | } |
91 | 4.37k | if( libfsapfs_container_open_file_io_handle( |
92 | 4.37k | container, |
93 | 4.37k | file_io_handle, |
94 | 4.37k | LIBFSAPFS_OPEN_READ, |
95 | 4.37k | NULL ) != 1 ) |
96 | 1.24k | { |
97 | 1.24k | goto on_error_libfsapfs_container; |
98 | 1.24k | } |
99 | 3.12k | if( libfsapfs_container_get_number_of_volumes( |
100 | 3.12k | container, |
101 | 3.12k | &number_of_volumes, |
102 | 3.12k | NULL ) != 1 ) |
103 | 0 | { |
104 | 0 | goto on_error_libfsapfs_container; |
105 | 0 | } |
106 | 3.12k | if( number_of_volumes > 0 ) |
107 | 3.08k | { |
108 | 3.08k | if( libfsapfs_container_get_volume_by_index( |
109 | 3.08k | container, |
110 | 3.08k | 0, |
111 | 3.08k | &volume, |
112 | 3.08k | NULL ) != 1 ) |
113 | 1.70k | { |
114 | 1.70k | goto on_error_libfsapfs_container; |
115 | 1.70k | } |
116 | 1.37k | if( libfsapfs_volume_get_root_directory( |
117 | 1.37k | volume, |
118 | 1.37k | &root_directory, |
119 | 1.37k | NULL ) == 1 ) |
120 | 771 | { |
121 | 771 | if( libfsapfs_file_entry_get_number_of_sub_file_entries( |
122 | 771 | root_directory, |
123 | 771 | &number_of_sub_file_entries, |
124 | 771 | NULL ) != 1 ) |
125 | 80 | { |
126 | 80 | goto on_error_libfsapfs_root_directory; |
127 | 80 | } |
128 | 691 | if( number_of_sub_file_entries > 0 ) |
129 | 608 | { |
130 | 608 | result = libfsapfs_file_entry_get_sub_file_entry_by_index( |
131 | 608 | root_directory, |
132 | 608 | 0, |
133 | 608 | &sub_file_entry, |
134 | 608 | NULL ); |
135 | | |
136 | 608 | if( result != -1 ) |
137 | 561 | { |
138 | 561 | libfsapfs_file_entry_get_identifier( |
139 | 561 | sub_file_entry, |
140 | 561 | &value_64bit, |
141 | 561 | NULL ); |
142 | | |
143 | 561 | libfsapfs_file_entry_get_parent_identifier( |
144 | 561 | sub_file_entry, |
145 | 561 | &value_64bit, |
146 | 561 | NULL ); |
147 | | |
148 | 561 | libfsapfs_file_entry_get_creation_time( |
149 | 561 | sub_file_entry, |
150 | 561 | &posix_time, |
151 | 561 | NULL ); |
152 | | |
153 | 561 | libfsapfs_file_entry_get_modification_time( |
154 | 561 | sub_file_entry, |
155 | 561 | &posix_time, |
156 | 561 | NULL ); |
157 | | |
158 | 561 | libfsapfs_file_entry_get_access_time( |
159 | 561 | sub_file_entry, |
160 | 561 | &posix_time, |
161 | 561 | NULL ); |
162 | | |
163 | 561 | libfsapfs_file_entry_get_inode_change_time( |
164 | 561 | sub_file_entry, |
165 | 561 | &posix_time, |
166 | 561 | NULL ); |
167 | | |
168 | 561 | libfsapfs_file_entry_get_added_time( |
169 | 561 | sub_file_entry, |
170 | 561 | &posix_time, |
171 | 561 | NULL ); |
172 | | |
173 | 561 | libfsapfs_file_entry_get_file_mode( |
174 | 561 | sub_file_entry, |
175 | 561 | &value_16bit, |
176 | 561 | NULL ); |
177 | | |
178 | 561 | libfsapfs_file_entry_get_number_of_links( |
179 | 561 | sub_file_entry, |
180 | 561 | &value_32bit, |
181 | 561 | NULL ); |
182 | | |
183 | 561 | libfsapfs_file_entry_get_owner_identifier( |
184 | 561 | sub_file_entry, |
185 | 561 | &value_32bit, |
186 | 561 | NULL ); |
187 | | |
188 | 561 | libfsapfs_file_entry_get_group_identifier( |
189 | 561 | sub_file_entry, |
190 | 561 | &value_32bit, |
191 | 561 | NULL ); |
192 | | |
193 | 561 | libfsapfs_file_entry_get_device_identifier( |
194 | 561 | sub_file_entry, |
195 | 561 | &value_32bit, |
196 | 561 | NULL ); |
197 | | |
198 | 561 | libfsapfs_file_entry_get_device_number( |
199 | 561 | sub_file_entry, |
200 | 561 | &major_device_number, |
201 | 561 | &minor_device_number, |
202 | 561 | NULL ); |
203 | | |
204 | 561 | libfsapfs_file_entry_get_utf8_name_size( |
205 | 561 | sub_file_entry, |
206 | 561 | &string_size, |
207 | 561 | NULL ); |
208 | | |
209 | 561 | libfsapfs_file_entry_get_utf8_name( |
210 | 561 | sub_file_entry, |
211 | 561 | string_value, |
212 | 561 | 64, |
213 | 561 | NULL ); |
214 | | |
215 | 561 | libfsapfs_file_entry_get_utf8_symbolic_link_target_size( |
216 | 561 | sub_file_entry, |
217 | 561 | &string_size, |
218 | 561 | NULL ); |
219 | | |
220 | 561 | libfsapfs_file_entry_get_utf8_symbolic_link_target( |
221 | 561 | sub_file_entry, |
222 | 561 | string_value, |
223 | 561 | 64, |
224 | 561 | NULL ); |
225 | | |
226 | 561 | libfsapfs_file_entry_get_offset( |
227 | 561 | sub_file_entry, |
228 | 561 | &file_offset, |
229 | 561 | NULL ); |
230 | | |
231 | 561 | libfsapfs_file_entry_get_size( |
232 | 561 | sub_file_entry, |
233 | 561 | &file_size, |
234 | 561 | NULL ); |
235 | | |
236 | 561 | libfsapfs_file_entry_get_number_of_extents( |
237 | 561 | sub_file_entry, |
238 | 561 | &number_of_extents, |
239 | 561 | NULL ); |
240 | 561 | } |
241 | 608 | libfsapfs_file_entry_free( |
242 | 608 | &sub_file_entry, |
243 | 608 | NULL ); |
244 | 608 | } |
245 | 771 | on_error_libfsapfs_root_directory: |
246 | 771 | libfsapfs_file_entry_free( |
247 | 771 | &root_directory, |
248 | 771 | NULL ); |
249 | 771 | } |
250 | 1.37k | libfsapfs_volume_free( |
251 | 1.37k | &volume, |
252 | 1.37k | NULL ); |
253 | 1.37k | } |
254 | 4.37k | on_error_libfsapfs_container: |
255 | 4.37k | libfsapfs_container_free( |
256 | 4.37k | &container, |
257 | 4.37k | NULL ); |
258 | | |
259 | 4.37k | on_error_libbfio: |
260 | 4.37k | libbfio_handle_free( |
261 | 4.37k | &file_io_handle, |
262 | 4.37k | NULL ); |
263 | | |
264 | 4.37k | return( 0 ); |
265 | 4.37k | } |
266 | | |
267 | | } /* extern "C" */ |
268 | | |