/src/libfsext/ossfuzz/volume_fuzzer.cc
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * OSS-Fuzz target for libfsext volume type  | 
3  |  |  *  | 
4  |  |  * Copyright (C) 2010-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_libfsext.h"  | 
31  |  |  | 
32  |  | #if !defined( LIBFSEXT_HAVE_BFIO )  | 
33  |  |  | 
34  |  | /* Opens a volume using a Basic File IO (bfio) handle  | 
35  |  |  * Returns 1 if successful or -1 on error  | 
36  |  |  */  | 
37  |  | LIBFSEXT_EXTERN \  | 
38  |  | int libfsext_volume_open_file_io_handle(  | 
39  |  |      libfsext_volume_t *volume,  | 
40  |  |      libbfio_handle_t *file_io_handle,  | 
41  |  |      int access_flags,  | 
42  |  |      libfsext_error_t **error );  | 
43  |  |  | 
44  |  | #endif /* !defined( LIBFSEXT_HAVE_BFIO ) */  | 
45  |  |  | 
46  |  | int LLVMFuzzerTestOneInput(  | 
47  |  |      const uint8_t *data,  | 
48  |  |      size_t size )  | 
49  | 785  | { | 
50  | 785  |   uint8_t volume_identifier[ 16 ];  | 
51  | 785  |   uint8_t string_value[ 64 ];  | 
52  |  |  | 
53  | 785  |   libbfio_handle_t *file_io_handle             = NULL;  | 
54  | 785  |   libfsext_volume_t *volume                    = NULL;  | 
55  | 785  |   size_t string_size                           = 0;  | 
56  | 785  |   uint32_t compatible_features_flags           = 0;  | 
57  | 785  |   uint32_t incompatible_features_flags         = 0;  | 
58  | 785  |   uint32_t number_of_file_entries              = 0;  | 
59  | 785  |   uint32_t read_only_compatible_features_flags = 0;  | 
60  | 785  |   int32_t posix_time                           = 0;  | 
61  | 785  |   uint8_t format_version                       = 0;  | 
62  | 785  |   int result                                   = 0;  | 
63  |  |  | 
64  | 785  |   if( libbfio_memory_range_initialize(  | 
65  | 785  |        &file_io_handle,  | 
66  | 785  |        NULL ) != 1 )  | 
67  | 0  |   { | 
68  | 0  |     return( 0 );  | 
69  | 0  |   }  | 
70  | 785  |   if( libbfio_memory_range_set(  | 
71  | 785  |        file_io_handle,  | 
72  | 785  |        (uint8_t *) data,  | 
73  | 785  |        size,  | 
74  | 785  |        NULL ) != 1 )  | 
75  | 0  |   { | 
76  | 0  |     goto on_error_libbfio;  | 
77  | 0  |   }  | 
78  | 785  |   if( libfsext_volume_initialize(  | 
79  | 785  |        &volume,  | 
80  | 785  |        NULL ) != 1 )  | 
81  | 0  |   { | 
82  | 0  |     goto on_error_libbfio;  | 
83  | 0  |   }  | 
84  | 785  |   result = libfsext_volume_open_file_io_handle(  | 
85  | 785  |             volume,  | 
86  | 785  |             file_io_handle,  | 
87  | 785  |             LIBFSEXT_OPEN_READ,  | 
88  | 785  |             NULL );  | 
89  |  |  | 
90  | 785  |   if( result != -1 )  | 
91  | 214  |   { | 
92  | 214  |     libfsext_volume_get_format_version(  | 
93  | 214  |      volume,  | 
94  | 214  |      &format_version,  | 
95  | 214  |      NULL );  | 
96  |  |  | 
97  | 214  |     libfsext_volume_get_features_flags(  | 
98  | 214  |      volume,  | 
99  | 214  |      &compatible_features_flags,  | 
100  | 214  |      &incompatible_features_flags,  | 
101  | 214  |      &read_only_compatible_features_flags,  | 
102  | 214  |      NULL );  | 
103  |  |  | 
104  | 214  |     libfsext_volume_get_identifier(  | 
105  | 214  |      volume,  | 
106  | 214  |      volume_identifier,  | 
107  | 214  |      16,  | 
108  | 214  |      NULL );  | 
109  |  |  | 
110  | 214  |     libfsext_volume_get_utf8_label_size(  | 
111  | 214  |      volume,  | 
112  | 214  |      &string_size,  | 
113  | 214  |      NULL );  | 
114  |  |  | 
115  | 214  |     libfsext_volume_get_utf8_label(  | 
116  | 214  |      volume,  | 
117  | 214  |      string_value,  | 
118  | 214  |      64,  | 
119  | 214  |      NULL );  | 
120  |  |  | 
121  | 214  |     libfsext_volume_get_utf8_last_mount_path_size(  | 
122  | 214  |      volume,  | 
123  | 214  |      &string_size,  | 
124  | 214  |      NULL );  | 
125  |  |  | 
126  | 214  |     libfsext_volume_get_utf8_last_mount_path(  | 
127  | 214  |      volume,  | 
128  | 214  |      string_value,  | 
129  | 214  |      64,  | 
130  | 214  |      NULL );  | 
131  |  |  | 
132  | 214  |     libfsext_volume_get_last_mount_time(  | 
133  | 214  |      volume,  | 
134  | 214  |      &posix_time,  | 
135  | 214  |      NULL );  | 
136  |  |  | 
137  | 214  |     libfsext_volume_get_last_written_time(  | 
138  | 214  |      volume,  | 
139  | 214  |      &posix_time,  | 
140  | 214  |      NULL );  | 
141  |  |  | 
142  | 214  |     libfsext_volume_get_number_of_file_entries(  | 
143  | 214  |      volume,  | 
144  | 214  |      &number_of_file_entries,  | 
145  | 214  |      NULL );  | 
146  |  |  | 
147  | 214  |     libfsext_volume_close(  | 
148  | 214  |      volume,  | 
149  | 214  |      NULL );  | 
150  | 214  |   }  | 
151  | 785  |   libfsext_volume_free(  | 
152  | 785  |    &volume,  | 
153  | 785  |    NULL );  | 
154  |  |  | 
155  | 785  | on_error_libbfio:  | 
156  | 785  |   libbfio_handle_free(  | 
157  | 785  |    &file_io_handle,  | 
158  | 785  |    NULL );  | 
159  |  |  | 
160  | 785  |   return( 0 );  | 
161  | 785  | }  | 
162  |  |  | 
163  |  | } /* extern "C" */  | 
164  |  |  |