/src/libscca/ossfuzz/volume_information_fuzzer.cc
Line | Count | Source |
1 | | /* |
2 | | * OSS-Fuzz target for libscca volume information type |
3 | | * |
4 | | * Copyright (C) 2011-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 | | /* Note that some of the OSS-Fuzz engines use C++ |
26 | | */ |
27 | | extern "C" { |
28 | | |
29 | | #include "ossfuzz_libbfio.h" |
30 | | #include "ossfuzz_libscca.h" |
31 | | |
32 | | #if !defined( LIBSCCA_HAVE_BFIO ) |
33 | | |
34 | | /* Opens a file using a Basic File IO (bfio) handle |
35 | | * Returns 1 if successful or -1 on error |
36 | | */ |
37 | | LIBSCCA_EXTERN \ |
38 | | int libscca_file_open_file_io_handle( |
39 | | libscca_file_t *file, |
40 | | libbfio_handle_t *file_io_handle, |
41 | | int access_flags, |
42 | | libscca_error_t **error ); |
43 | | |
44 | | #endif /* !defined( LIBSCCA_HAVE_BFIO ) */ |
45 | | |
46 | | int LLVMFuzzerTestOneInput( |
47 | | const uint8_t *data, |
48 | | size_t size ) |
49 | 2.16k | { |
50 | 2.16k | uint8_t utf8_string[ 512 ]; |
51 | 2.16k | uint16_t utf16_string[ 256 ]; |
52 | | |
53 | 2.16k | libbfio_handle_t *file_io_handle = NULL; |
54 | 2.16k | libscca_file_t *file = NULL; |
55 | 2.16k | libscca_volume_information_t *volume_information = NULL; |
56 | 2.16k | size_t utf8_string_size = 0; |
57 | 2.16k | size_t utf16_string_size = 0; |
58 | 2.16k | uint64_t creation_time = 0; |
59 | 2.16k | uint32_t serial_number = 0; |
60 | 2.16k | int number_of_volumes = 0; |
61 | | |
62 | 2.16k | if( libbfio_memory_range_initialize( |
63 | 2.16k | &file_io_handle, |
64 | 2.16k | NULL ) != 1 ) |
65 | 0 | { |
66 | 0 | return( 0 ); |
67 | 0 | } |
68 | 2.16k | if( libbfio_memory_range_set( |
69 | 2.16k | file_io_handle, |
70 | 2.16k | (uint8_t *) data, |
71 | 2.16k | size, |
72 | 2.16k | NULL ) != 1 ) |
73 | 0 | { |
74 | 0 | goto on_error_libbfio; |
75 | 0 | } |
76 | 2.16k | if( libscca_file_initialize( |
77 | 2.16k | &file, |
78 | 2.16k | NULL ) != 1 ) |
79 | 0 | { |
80 | 0 | goto on_error_libbfio; |
81 | 0 | } |
82 | 2.16k | if( libscca_file_open_file_io_handle( |
83 | 2.16k | file, |
84 | 2.16k | file_io_handle, |
85 | 2.16k | LIBSCCA_OPEN_READ, |
86 | 2.16k | NULL ) != 1 ) |
87 | 1.91k | { |
88 | 1.91k | goto on_error_libscca; |
89 | 1.91k | } |
90 | 248 | if( libscca_file_get_number_of_volumes( |
91 | 248 | file, |
92 | 248 | &number_of_volumes, |
93 | 248 | NULL ) != 1 ) |
94 | 0 | { |
95 | 0 | goto on_error_libscca; |
96 | 0 | } |
97 | 248 | if( number_of_volumes > 0 ) |
98 | 203 | { |
99 | 203 | if( libscca_file_get_volume_information( |
100 | 203 | file, |
101 | 203 | 0, |
102 | 203 | &volume_information, |
103 | 203 | NULL ) != 1 ) |
104 | 0 | { |
105 | 0 | goto on_error_libscca; |
106 | 0 | } |
107 | 203 | if( libscca_volume_information_get_creation_time( |
108 | 203 | volume_information, |
109 | 203 | &creation_time, |
110 | 203 | NULL ) != 1 ) |
111 | 0 | { |
112 | 0 | goto on_error_libscca_volume_information; |
113 | 0 | } |
114 | 203 | if( libscca_volume_information_get_serial_number( |
115 | 203 | volume_information, |
116 | 203 | &serial_number, |
117 | 203 | NULL ) != 1 ) |
118 | 0 | { |
119 | 0 | goto on_error_libscca_volume_information; |
120 | 0 | } |
121 | 203 | if( libscca_volume_information_get_utf8_device_path_size( |
122 | 203 | volume_information, |
123 | 203 | &utf8_string_size, |
124 | 203 | NULL ) != 1 ) |
125 | 59 | { |
126 | 59 | goto on_error_libscca_volume_information; |
127 | 59 | } |
128 | 144 | if( libscca_volume_information_get_utf8_device_path( |
129 | 144 | volume_information, |
130 | 144 | utf8_string, |
131 | 144 | 512, |
132 | 144 | NULL ) != 1 ) |
133 | 9 | { |
134 | 9 | goto on_error_libscca_volume_information; |
135 | 9 | } |
136 | 135 | if( libscca_volume_information_get_utf16_device_path_size( |
137 | 135 | volume_information, |
138 | 135 | &utf16_string_size, |
139 | 135 | NULL ) != 1 ) |
140 | 0 | { |
141 | 0 | goto on_error_libscca_volume_information; |
142 | 0 | } |
143 | 135 | if( libscca_volume_information_get_utf16_device_path( |
144 | 135 | volume_information, |
145 | 135 | utf16_string, |
146 | 135 | 256, |
147 | 135 | NULL ) != 1 ) |
148 | 0 | { |
149 | 0 | goto on_error_libscca_volume_information; |
150 | 0 | } |
151 | 203 | on_error_libscca_volume_information: |
152 | 203 | libscca_volume_information_free( |
153 | 203 | &volume_information, |
154 | 203 | NULL ); |
155 | 203 | } |
156 | 248 | libscca_file_close( |
157 | 248 | file, |
158 | 248 | NULL ); |
159 | | |
160 | 2.16k | on_error_libscca: |
161 | 2.16k | libscca_file_free( |
162 | 2.16k | &file, |
163 | 2.16k | NULL ); |
164 | | |
165 | 2.16k | on_error_libbfio: |
166 | 2.16k | libbfio_handle_free( |
167 | 2.16k | &file_io_handle, |
168 | 2.16k | NULL ); |
169 | | |
170 | 2.16k | return( 0 ); |
171 | 2.16k | } |
172 | | |
173 | | } /* extern "C" */ |