/src/libregf/ossfuzz/key_fuzzer.cc
Line | Count | Source |
1 | | /* |
2 | | * OSS-Fuzz target for libregf key type |
3 | | * |
4 | | * Copyright (C) 2009-2026, 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 | | #include <stdlib.h> |
26 | | |
27 | | /* Note that some of the OSS-Fuzz engines use C++ |
28 | | */ |
29 | | extern "C" { |
30 | | |
31 | | #include "ossfuzz_libbfio.h" |
32 | | #include "ossfuzz_libregf.h" |
33 | | |
34 | | #if !defined( LIBREGF_HAVE_BFIO ) |
35 | | |
36 | | /* Opens a file using a Basic File IO (bfio) handle |
37 | | * Returns 1 if successful or -1 on error |
38 | | */ |
39 | | LIBREGF_EXTERN \ |
40 | | int libregf_file_open_file_io_handle( |
41 | | libregf_file_t *file, |
42 | | libbfio_handle_t *file_io_handle, |
43 | | int access_flags, |
44 | | libregf_error_t **error ); |
45 | | |
46 | | #endif /* !defined( LIBREGF_HAVE_BFIO ) */ |
47 | | |
48 | | /* Limits on the traversal and buffer sizes to bound the time a single input takes |
49 | | */ |
50 | 2.63k | #define FUZZER_KEY_LIMIT 4 |
51 | 14.4k | #define FUZZER_STRING_SIZE_LIMIT ( (size_t) 0x00100000 ) |
52 | 3.95k | #define FUZZER_LOOKUP_STRING_LIMIT ( (size_t) 0x4000 ) |
53 | 745 | #define FUZZER_KEY_DEPTH_LIMIT 7 |
54 | | |
55 | | /* The ASCII codepages supported by libregf_file_set_ascii_codepage |
56 | | */ |
57 | | static const int value_codepages[] = { |
58 | | LIBREGF_CODEPAGE_ASCII, |
59 | | LIBREGF_CODEPAGE_WINDOWS_874, |
60 | | LIBREGF_CODEPAGE_WINDOWS_932, |
61 | | LIBREGF_CODEPAGE_WINDOWS_936, |
62 | | LIBREGF_CODEPAGE_WINDOWS_949, |
63 | | LIBREGF_CODEPAGE_WINDOWS_950, |
64 | | LIBREGF_CODEPAGE_WINDOWS_1250, |
65 | | LIBREGF_CODEPAGE_WINDOWS_1251, |
66 | | LIBREGF_CODEPAGE_WINDOWS_1252, |
67 | | LIBREGF_CODEPAGE_WINDOWS_1253, |
68 | | LIBREGF_CODEPAGE_WINDOWS_1254, |
69 | | LIBREGF_CODEPAGE_WINDOWS_1255, |
70 | | LIBREGF_CODEPAGE_WINDOWS_1256, |
71 | | LIBREGF_CODEPAGE_WINDOWS_1257, |
72 | | LIBREGF_CODEPAGE_WINDOWS_1258, |
73 | | }; |
74 | | |
75 | | static const size_t value_number_of_codepages = |
76 | | sizeof( value_codepages ) / sizeof( value_codepages[ 0 ] ); |
77 | | |
78 | | /* Decodes the name and metadata of a key using the typed accessors |
79 | | * Returns 1 if successful or -1 on error |
80 | | */ |
81 | | int key_decode_fuzzer( |
82 | | libregf_key_t *key ) |
83 | 4.17k | { |
84 | 4.17k | uint8_t *name = NULL; |
85 | 4.17k | uint8_t *utf8_string = NULL; |
86 | 4.17k | uint16_t *utf16_string = NULL; |
87 | 4.17k | off64_t key_offset = 0; |
88 | 4.17k | size_t name_size = 0; |
89 | 4.17k | size_t utf8_string_size = 0; |
90 | 4.17k | size_t utf16_string_size = 0; |
91 | 4.17k | uint8_t name_byte = 0; |
92 | 4.17k | uint64_t filetime = 0; |
93 | 4.17k | int result = 1; |
94 | | |
95 | 4.17k | if( key == NULL ) |
96 | 0 | { |
97 | 0 | return( -1 ); |
98 | 0 | } |
99 | 4.17k | libregf_key_get_offset( |
100 | 4.17k | key, |
101 | 4.17k | &key_offset, |
102 | 4.17k | NULL ); |
103 | | |
104 | 4.17k | libregf_key_is_corrupted( |
105 | 4.17k | key, |
106 | 4.17k | NULL ); |
107 | | |
108 | 4.17k | libregf_key_get_last_written_time( |
109 | 4.17k | key, |
110 | 4.17k | &filetime, |
111 | 4.17k | NULL ); |
112 | | |
113 | 4.17k | result = libregf_key_get_name_size( |
114 | 4.17k | key, |
115 | 4.17k | &name_size, |
116 | 4.17k | NULL ); |
117 | | |
118 | 4.17k | if( ( result == 1 ) |
119 | 4.17k | && ( name_size > 0 ) |
120 | 4.17k | && ( name_size <= FUZZER_STRING_SIZE_LIMIT ) ) |
121 | 4.17k | { |
122 | 4.17k | name = (uint8_t *) malloc( name_size ); |
123 | | |
124 | 4.17k | if( name != NULL ) |
125 | 4.17k | { |
126 | 4.17k | if( libregf_key_get_name( |
127 | 4.17k | key, |
128 | 4.17k | name, |
129 | 4.17k | name_size, |
130 | 4.17k | NULL ) == 1 ) |
131 | 4.17k | { |
132 | 4.17k | name_byte = name[ 0 ]; |
133 | 4.17k | } |
134 | 4.17k | free( name ); |
135 | 4.17k | } |
136 | 4.17k | } |
137 | 4.17k | result = libregf_key_get_utf8_name_size( |
138 | 4.17k | key, |
139 | 4.17k | &utf8_string_size, |
140 | 4.17k | NULL ); |
141 | | |
142 | 4.17k | if( ( result == 1 ) |
143 | 4.17k | && ( utf8_string_size > 0 ) |
144 | 4.07k | && ( utf8_string_size <= FUZZER_STRING_SIZE_LIMIT ) ) |
145 | 4.07k | { |
146 | 4.07k | utf8_string = (uint8_t *) malloc( utf8_string_size ); |
147 | | |
148 | 4.07k | if( utf8_string != NULL ) |
149 | 4.07k | { |
150 | 4.07k | if( libregf_key_get_utf8_name( |
151 | 4.07k | key, |
152 | 4.07k | utf8_string, |
153 | 4.07k | utf8_string_size, |
154 | 4.07k | NULL ) == 1 ) |
155 | 4.07k | { |
156 | 4.07k | name_byte ^= utf8_string[ 0 ]; |
157 | 4.07k | } |
158 | 4.07k | free( utf8_string ); |
159 | 4.07k | } |
160 | 4.07k | } |
161 | | /* The size is the number of UTF-16 characters, |
162 | | * including the end of string character |
163 | | */ |
164 | 4.17k | result = libregf_key_get_utf16_name_size( |
165 | 4.17k | key, |
166 | 4.17k | &utf16_string_size, |
167 | 4.17k | NULL ); |
168 | | |
169 | 4.17k | if( ( result == 1 ) |
170 | 4.17k | && ( utf16_string_size > 0 ) |
171 | 4.07k | && ( utf16_string_size <= FUZZER_STRING_SIZE_LIMIT ) ) |
172 | 4.07k | { |
173 | 4.07k | utf16_string = (uint16_t *) malloc( utf16_string_size * sizeof( uint16_t ) ); |
174 | | |
175 | 4.07k | if( utf16_string != NULL ) |
176 | 4.07k | { |
177 | 4.07k | if( libregf_key_get_utf16_name( |
178 | 4.07k | key, |
179 | 4.07k | utf16_string, |
180 | 4.07k | utf16_string_size, |
181 | 4.07k | NULL ) == 1 ) |
182 | 4.07k | { |
183 | 4.07k | name_byte ^= (uint8_t) utf16_string[ 0 ]; |
184 | 4.07k | } |
185 | 4.07k | free( utf16_string ); |
186 | 4.07k | } |
187 | 4.07k | } |
188 | 4.17k | result = libregf_key_get_class_name_size( |
189 | 4.17k | key, |
190 | 4.17k | &name_size, |
191 | 4.17k | NULL ); |
192 | | |
193 | 4.17k | if( ( result == 1 ) |
194 | 727 | && ( name_size > 0 ) |
195 | 727 | && ( name_size <= FUZZER_STRING_SIZE_LIMIT ) ) |
196 | 727 | { |
197 | 727 | name = (uint8_t *) malloc( name_size ); |
198 | | |
199 | 727 | if( name != NULL ) |
200 | 727 | { |
201 | 727 | if( libregf_key_get_class_name( |
202 | 727 | key, |
203 | 727 | name, |
204 | 727 | name_size, |
205 | 727 | NULL ) == 1 ) |
206 | 727 | { |
207 | 727 | name_byte ^= name[ 0 ]; |
208 | 727 | } |
209 | 727 | free( name ); |
210 | 727 | } |
211 | 727 | } |
212 | 4.17k | result = libregf_key_get_utf8_class_name_size( |
213 | 4.17k | key, |
214 | 4.17k | &utf8_string_size, |
215 | 4.17k | NULL ); |
216 | | |
217 | 4.17k | if( ( result == 1 ) |
218 | 504 | && ( utf8_string_size > 0 ) |
219 | 504 | && ( utf8_string_size <= FUZZER_STRING_SIZE_LIMIT ) ) |
220 | 504 | { |
221 | 504 | utf8_string = (uint8_t *) malloc( utf8_string_size ); |
222 | | |
223 | 504 | if( utf8_string != NULL ) |
224 | 504 | { |
225 | 504 | if( libregf_key_get_utf8_class_name( |
226 | 504 | key, |
227 | 504 | utf8_string, |
228 | 504 | utf8_string_size, |
229 | 504 | NULL ) == 1 ) |
230 | 504 | { |
231 | 504 | name_byte ^= utf8_string[ 0 ]; |
232 | 504 | } |
233 | 504 | free( utf8_string ); |
234 | 504 | } |
235 | 504 | } |
236 | | /* The size is the number of UTF-16 characters, |
237 | | * including the end of string character |
238 | | */ |
239 | 4.17k | result = libregf_key_get_utf16_class_name_size( |
240 | 4.17k | key, |
241 | 4.17k | &utf16_string_size, |
242 | 4.17k | NULL ); |
243 | | |
244 | 4.17k | if( ( result == 1 ) |
245 | 504 | && ( utf16_string_size > 0 ) |
246 | 504 | && ( utf16_string_size <= FUZZER_STRING_SIZE_LIMIT ) ) |
247 | 504 | { |
248 | 504 | utf16_string = (uint16_t *) malloc( utf16_string_size * sizeof( uint16_t ) ); |
249 | | |
250 | 504 | if( utf16_string != NULL ) |
251 | 504 | { |
252 | 504 | if( libregf_key_get_utf16_class_name( |
253 | 504 | key, |
254 | 504 | utf16_string, |
255 | 504 | utf16_string_size, |
256 | 504 | NULL ) == 1 ) |
257 | 504 | { |
258 | 504 | name_byte ^= (uint8_t) utf16_string[ 0 ]; |
259 | 504 | } |
260 | 504 | free( utf16_string ); |
261 | 504 | } |
262 | 504 | } |
263 | 4.17k | result = libregf_key_get_security_descriptor_size( |
264 | 4.17k | key, |
265 | 4.17k | &name_size, |
266 | 4.17k | NULL ); |
267 | | |
268 | 4.17k | if( ( result == 1 ) |
269 | 376 | && ( name_size > 0 ) |
270 | 376 | && ( name_size <= FUZZER_STRING_SIZE_LIMIT ) ) |
271 | 376 | { |
272 | 376 | name = (uint8_t *) malloc( name_size ); |
273 | | |
274 | 376 | if( name != NULL ) |
275 | 376 | { |
276 | 376 | if( libregf_key_get_security_descriptor( |
277 | 376 | key, |
278 | 376 | name, |
279 | 376 | name_size, |
280 | 376 | NULL ) == 1 ) |
281 | 376 | { |
282 | 376 | name_byte ^= name[ 0 ]; |
283 | 376 | } |
284 | 376 | free( name ); |
285 | 376 | } |
286 | 376 | } |
287 | | /* Use the decoded values as a sink to keep them live |
288 | | */ |
289 | 4.17k | if( ( name_byte ^ (uint8_t) key_offset ^ (uint8_t) filetime ) != 0 ) |
290 | 4.17k | { |
291 | | /* No action required |
292 | | */ |
293 | 4.17k | } |
294 | 4.17k | return( 1 ); |
295 | 4.17k | } |
296 | | |
297 | | /* Walks a depth-driven path into the registry tree and decodes |
298 | | * each key along the path. The sub key index at each level is |
299 | | * selected from the fuzz data (data[ 4 + level ]), which steers |
300 | | * the traversal toward different parts of the tree during |
301 | | * fuzzing |
302 | | * The parent key is not freed by this function |
303 | | * Returns 1 if successful or -1 on error |
304 | | */ |
305 | | int key_spine_fuzzer( |
306 | | libregf_key_t *parent_key, |
307 | | int level, |
308 | | int max_level, |
309 | | const uint8_t *data, |
310 | | size_t size ) |
311 | 2.58k | { |
312 | 2.58k | libregf_key_t *key = NULL; |
313 | 2.58k | int number_of_sub_keys = 0; |
314 | 2.58k | int sub_key_index = 0; |
315 | 2.58k | int result = 1; |
316 | | |
317 | 2.58k | if( parent_key == NULL ) |
318 | 0 | { |
319 | 0 | return( -1 ); |
320 | 0 | } |
321 | 2.58k | if( level > max_level |
322 | 2.37k | || size < ( size_t ) level + 5 ) |
323 | 206 | { |
324 | 206 | return( 1 ); |
325 | 206 | } |
326 | 2.37k | if( libregf_key_get_number_of_sub_keys( |
327 | 2.37k | parent_key, |
328 | 2.37k | &number_of_sub_keys, |
329 | 2.37k | NULL ) != 1 |
330 | 2.37k | || number_of_sub_keys <= 0 ) |
331 | 101 | { |
332 | 101 | return( 1 ); |
333 | 101 | } |
334 | 2.27k | sub_key_index = ( int ) ( data[ 4 + level ] % ( size_t ) number_of_sub_keys ); |
335 | | |
336 | 2.27k | key = NULL; |
337 | | |
338 | 2.27k | if( libregf_key_get_sub_key_by_index( |
339 | 2.27k | parent_key, |
340 | 2.27k | sub_key_index, |
341 | 2.27k | &key, |
342 | 2.27k | NULL ) != 1 ) |
343 | 438 | { |
344 | 438 | return( 1 ); |
345 | 438 | } |
346 | 1.83k | result = key_decode_fuzzer( |
347 | 1.83k | key ); |
348 | | |
349 | 1.83k | result = key_spine_fuzzer( |
350 | 1.83k | key, |
351 | 1.83k | level + 1, |
352 | 1.83k | max_level, |
353 | 1.83k | data, |
354 | 1.83k | size ); |
355 | | |
356 | 1.83k | libregf_key_free( |
357 | 1.83k | &key, |
358 | 1.83k | NULL ); |
359 | | |
360 | 1.83k | return( result ); |
361 | 2.27k | } |
362 | | |
363 | | int LLVMFuzzerTestOneInput( |
364 | | const uint8_t *data, |
365 | | size_t size ) |
366 | 2.06k | { |
367 | 2.06k | libbfio_handle_t *file_io_handle = NULL; |
368 | 2.06k | libregf_file_t *file = NULL; |
369 | 2.06k | libregf_key_t *root_key = NULL; |
370 | 2.06k | libregf_key_t *sub_key = NULL; |
371 | 2.06k | libregf_key_t *sub_sub_key = NULL; |
372 | 2.06k | libregf_key_t *lookup_key = NULL; |
373 | 2.06k | libregf_value_t *value = NULL; |
374 | 2.06k | uint16_t *utf16_lookup_string = NULL; |
375 | 2.06k | size_t index = 0; |
376 | 2.06k | size_t utf8_lookup_string_length = 0; |
377 | 2.06k | size_t utf16_lookup_string_length = 0; |
378 | 2.06k | int number_of_sub_keys = 0; |
379 | 2.06k | int sub_key_index = 0; |
380 | | |
381 | 2.06k | if( libbfio_memory_range_initialize( |
382 | 2.06k | &file_io_handle, |
383 | 2.06k | NULL ) != 1 ) |
384 | 0 | { |
385 | 0 | return( 0 ); |
386 | 0 | } |
387 | 2.06k | if( libbfio_memory_range_set( |
388 | 2.06k | file_io_handle, |
389 | 2.06k | (uint8_t *) data, |
390 | 2.06k | size, |
391 | 2.06k | NULL ) != 1 ) |
392 | 0 | { |
393 | 0 | goto on_error_libbfio; |
394 | 0 | } |
395 | 2.06k | if( libregf_file_initialize( |
396 | 2.06k | &file, |
397 | 2.06k | NULL ) != 1 ) |
398 | 0 | { |
399 | 0 | goto on_error_libbfio; |
400 | 0 | } |
401 | 2.06k | if( libregf_file_open_file_io_handle( |
402 | 2.06k | file, |
403 | 2.06k | file_io_handle, |
404 | 2.06k | LIBREGF_OPEN_READ, |
405 | 2.06k | NULL ) != 1 ) |
406 | 402 | { |
407 | 402 | goto on_error_libregf_file; |
408 | 402 | } |
409 | | /* The codepage is selected from the fuzz data to steer the |
410 | | * codepage conversion of key names |
411 | | */ |
412 | 1.66k | if( size > 0 ) |
413 | 1.66k | { |
414 | 1.66k | libregf_file_set_ascii_codepage( |
415 | 1.66k | file, |
416 | 1.66k | value_codepages[ data[ 0 ] % value_number_of_codepages ], |
417 | 1.66k | NULL ); |
418 | 1.66k | } |
419 | 1.66k | utf8_lookup_string_length = size; |
420 | | |
421 | 1.66k | if( utf8_lookup_string_length > FUZZER_LOOKUP_STRING_LIMIT ) |
422 | 328 | { |
423 | 328 | utf8_lookup_string_length = FUZZER_LOOKUP_STRING_LIMIT; |
424 | 328 | } |
425 | 1.66k | utf16_lookup_string_length = ( size / 2 ); |
426 | | |
427 | 1.66k | if( utf16_lookup_string_length > FUZZER_LOOKUP_STRING_LIMIT ) |
428 | 304 | { |
429 | 304 | utf16_lookup_string_length = FUZZER_LOOKUP_STRING_LIMIT; |
430 | 304 | } |
431 | 1.66k | if( utf16_lookup_string_length > 0 ) |
432 | 1.66k | { |
433 | 1.66k | utf16_lookup_string = (uint16_t *) malloc( utf16_lookup_string_length * sizeof( uint16_t ) ); |
434 | | |
435 | 1.66k | if( utf16_lookup_string != NULL ) |
436 | 1.66k | { |
437 | 1.66k | for( index = 0; |
438 | 8.40M | index < utf16_lookup_string_length; |
439 | 8.40M | index++ ) |
440 | 8.40M | { |
441 | 8.40M | utf16_lookup_string[ index ] = (uint16_t) ( data[ index * 2 ] | ( (uint16_t) data[ index * 2 + 1 ] << 8 ) ); |
442 | 8.40M | } |
443 | 1.66k | } |
444 | 1.66k | } |
445 | 1.66k | if( libregf_file_get_root_key( |
446 | 1.66k | file, |
447 | 1.66k | &root_key, |
448 | 1.66k | NULL ) == 1 ) |
449 | 745 | { |
450 | 745 | key_decode_fuzzer( |
451 | 745 | root_key ); |
452 | | |
453 | | /* Searches for sub keys using names and paths derived from |
454 | | * the fuzz data. The data is not necessarily valid UTF-8 |
455 | | * or UTF-16 which exercises the validation and conversion |
456 | | * error paths in the library |
457 | | */ |
458 | 745 | if( utf8_lookup_string_length > 0 ) |
459 | 745 | { |
460 | 745 | lookup_key = NULL; |
461 | | |
462 | 745 | libregf_key_get_sub_key_by_utf8_name( |
463 | 745 | root_key, |
464 | 745 | data, |
465 | 745 | utf8_lookup_string_length, |
466 | 745 | &lookup_key, |
467 | 745 | NULL ); |
468 | | |
469 | 745 | if( lookup_key != NULL ) |
470 | 0 | { |
471 | 0 | key_decode_fuzzer( |
472 | 0 | lookup_key ); |
473 | |
|
474 | 0 | libregf_key_free( |
475 | 0 | &lookup_key, |
476 | 0 | NULL ); |
477 | 0 | } |
478 | 745 | lookup_key = NULL; |
479 | | |
480 | 745 | libregf_key_get_sub_key_by_utf8_path( |
481 | 745 | root_key, |
482 | 745 | data, |
483 | 745 | utf8_lookup_string_length, |
484 | 745 | &lookup_key, |
485 | 745 | NULL ); |
486 | | |
487 | 745 | if( lookup_key != NULL ) |
488 | 0 | { |
489 | 0 | libregf_key_free( |
490 | 0 | &lookup_key, |
491 | 0 | NULL ); |
492 | 0 | } |
493 | 745 | lookup_key = NULL; |
494 | | |
495 | 745 | value = NULL; |
496 | | |
497 | 745 | libregf_key_get_value_by_utf8_name( |
498 | 745 | root_key, |
499 | 745 | data, |
500 | 745 | utf8_lookup_string_length, |
501 | 745 | &value, |
502 | 745 | NULL ); |
503 | | |
504 | 745 | if( value != NULL ) |
505 | 0 | { |
506 | 0 | libregf_value_free( |
507 | 0 | &value, |
508 | 0 | NULL ); |
509 | 0 | } |
510 | 745 | value = NULL; |
511 | 745 | } |
512 | | /* Retrieves the default value |
513 | | */ |
514 | 745 | value = NULL; |
515 | | |
516 | 745 | libregf_key_get_value_by_utf8_name( |
517 | 745 | root_key, |
518 | 745 | NULL, |
519 | 745 | 0, |
520 | 745 | &value, |
521 | 745 | NULL ); |
522 | | |
523 | 745 | if( value != NULL ) |
524 | 289 | { |
525 | 289 | libregf_value_free( |
526 | 289 | &value, |
527 | 289 | NULL ); |
528 | 289 | } |
529 | 745 | value = NULL; |
530 | | |
531 | 745 | if( ( utf16_lookup_string != NULL ) |
532 | 745 | && ( utf16_lookup_string_length > 0 ) ) |
533 | 745 | { |
534 | 745 | lookup_key = NULL; |
535 | | |
536 | 745 | libregf_key_get_sub_key_by_utf16_name( |
537 | 745 | root_key, |
538 | 745 | utf16_lookup_string, |
539 | 745 | utf16_lookup_string_length, |
540 | 745 | &lookup_key, |
541 | 745 | NULL ); |
542 | | |
543 | 745 | if( lookup_key != NULL ) |
544 | 0 | { |
545 | 0 | key_decode_fuzzer( |
546 | 0 | lookup_key ); |
547 | |
|
548 | 0 | libregf_key_free( |
549 | 0 | &lookup_key, |
550 | 0 | NULL ); |
551 | 0 | } |
552 | 745 | lookup_key = NULL; |
553 | | |
554 | 745 | libregf_key_get_sub_key_by_utf16_path( |
555 | 745 | root_key, |
556 | 745 | utf16_lookup_string, |
557 | 745 | utf16_lookup_string_length, |
558 | 745 | &lookup_key, |
559 | 745 | NULL ); |
560 | | |
561 | 745 | if( lookup_key != NULL ) |
562 | 0 | { |
563 | 0 | libregf_key_free( |
564 | 0 | &lookup_key, |
565 | 0 | NULL ); |
566 | 0 | } |
567 | 745 | lookup_key = NULL; |
568 | | |
569 | 745 | value = NULL; |
570 | | |
571 | 745 | libregf_key_get_value_by_utf16_name( |
572 | 745 | root_key, |
573 | 745 | utf16_lookup_string, |
574 | 745 | utf16_lookup_string_length, |
575 | 745 | &value, |
576 | 745 | NULL ); |
577 | | |
578 | 745 | if( value != NULL ) |
579 | 0 | { |
580 | 0 | libregf_value_free( |
581 | 0 | &value, |
582 | 0 | NULL ); |
583 | 0 | } |
584 | 745 | value = NULL; |
585 | 745 | } |
586 | 745 | if( libregf_key_get_number_of_sub_keys( |
587 | 745 | root_key, |
588 | 745 | &number_of_sub_keys, |
589 | 745 | NULL ) == 1 ) |
590 | 745 | { |
591 | 745 | for( sub_key_index = 0; |
592 | 3.01k | sub_key_index < number_of_sub_keys; |
593 | 2.26k | sub_key_index++ ) |
594 | 2.63k | { |
595 | 2.63k | if( sub_key_index >= FUZZER_KEY_LIMIT ) |
596 | 366 | { |
597 | 366 | break; |
598 | 366 | } |
599 | 2.26k | sub_key = NULL; |
600 | | |
601 | 2.26k | if( libregf_key_get_sub_key_by_index( |
602 | 2.26k | root_key, |
603 | 2.26k | sub_key_index, |
604 | 2.26k | &sub_key, |
605 | 2.26k | NULL ) != 1 ) |
606 | 1.38k | { |
607 | 1.38k | continue; |
608 | 1.38k | } |
609 | 882 | key_decode_fuzzer( |
610 | 882 | sub_key ); |
611 | | |
612 | | /* Decodes a sub sub key |
613 | | */ |
614 | 882 | sub_sub_key = NULL; |
615 | | |
616 | 882 | if( libregf_key_get_number_of_sub_keys( |
617 | 882 | sub_key, |
618 | 882 | &number_of_sub_keys, |
619 | 882 | NULL ) == 1 ) |
620 | 882 | { |
621 | 882 | if( number_of_sub_keys > 0 ) |
622 | 791 | { |
623 | 791 | if( libregf_key_get_sub_key_by_index( |
624 | 791 | sub_key, |
625 | 791 | 0, |
626 | 791 | &sub_sub_key, |
627 | 791 | NULL ) == 1 ) |
628 | 707 | { |
629 | 707 | key_decode_fuzzer( |
630 | 707 | sub_sub_key ); |
631 | | |
632 | 707 | libregf_key_free( |
633 | 707 | &sub_sub_key, |
634 | 707 | NULL ); |
635 | 707 | } |
636 | 791 | } |
637 | 882 | } |
638 | | |
639 | | /* Retrieves a value by name derived from the fuzz data. |
640 | | * The data is not necessarily valid UTF-8 or UTF-16 |
641 | | * which exercises the validation and conversion error |
642 | | * paths in the library |
643 | | */ |
644 | 882 | if( utf8_lookup_string_length > 0 ) |
645 | 882 | { |
646 | 882 | value = NULL; |
647 | | |
648 | 882 | libregf_key_get_value_by_utf8_name( |
649 | 882 | sub_key, |
650 | 882 | data, |
651 | 882 | utf8_lookup_string_length, |
652 | 882 | &value, |
653 | 882 | NULL ); |
654 | | |
655 | 882 | if( value != NULL ) |
656 | 0 | { |
657 | 0 | libregf_value_free( |
658 | 0 | &value, |
659 | 0 | NULL ); |
660 | 0 | } |
661 | 882 | value = NULL; |
662 | 882 | } |
663 | 882 | if( ( utf16_lookup_string != NULL ) |
664 | 882 | && ( utf16_lookup_string_length > 0 ) ) |
665 | 882 | { |
666 | 882 | value = NULL; |
667 | | |
668 | 882 | libregf_key_get_value_by_utf16_name( |
669 | 882 | sub_key, |
670 | 882 | utf16_lookup_string, |
671 | 882 | utf16_lookup_string_length, |
672 | 882 | &value, |
673 | 882 | NULL ); |
674 | | |
675 | 882 | if( value != NULL ) |
676 | 0 | { |
677 | 0 | libregf_value_free( |
678 | 0 | &value, |
679 | 0 | NULL ); |
680 | 0 | } |
681 | 882 | value = NULL; |
682 | 882 | } |
683 | 882 | libregf_key_free( |
684 | 882 | &sub_key, |
685 | 882 | NULL ); |
686 | 882 | } |
687 | 745 | } |
688 | | /* Decodes a depth-driven path into the registry tree, |
689 | | * which exercises keys at deeper levels |
690 | | */ |
691 | 745 | key_spine_fuzzer( |
692 | 745 | root_key, |
693 | 745 | 1, |
694 | 745 | FUZZER_KEY_DEPTH_LIMIT, |
695 | 745 | data, |
696 | 745 | size ); |
697 | | |
698 | 745 | libregf_key_free( |
699 | 745 | &root_key, |
700 | 745 | NULL ); |
701 | 745 | } |
702 | 1.66k | libregf_file_close( |
703 | 1.66k | file, |
704 | 1.66k | NULL ); |
705 | | |
706 | 2.06k | on_error_libregf_file: |
707 | 2.06k | free( utf16_lookup_string ); |
708 | 2.06k | libregf_file_free( |
709 | 2.06k | &file, |
710 | 2.06k | NULL ); |
711 | | |
712 | 2.06k | on_error_libbfio: |
713 | 2.06k | libbfio_handle_free( |
714 | 2.06k | &file_io_handle, |
715 | 2.06k | NULL ); |
716 | | |
717 | 2.06k | return( 0 ); |
718 | 2.06k | } |
719 | | |
720 | | } /* extern "C" */ |