/src/libfmapi/ossfuzz/one_off_entry_identifier_fuzzer.cc
Line | Count | Source |
1 | | /* |
2 | | * OSS-Fuzz target for libfmapi one_off_entry_identifier 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 | | #include <stdlib.h> |
25 | | |
26 | | /* Note that some of the OSS-Fuzz engines use C++ |
27 | | */ |
28 | | extern "C" { |
29 | | |
30 | | #include "ossfuzz_libfmapi.h" |
31 | | |
32 | | int LLVMFuzzerTestOneInput( |
33 | | const uint8_t *data, |
34 | | size_t size ) |
35 | 1.06k | { |
36 | 1.06k | char error_string[ 4096 ] = { 0 }; |
37 | | |
38 | 1.06k | libfmapi_error_t *error = NULL; |
39 | | |
40 | 1.06k | libfmapi_one_off_entry_identifier_t *one_off_entry_identifier = NULL; |
41 | | |
42 | 1.06k | uint16_t format_version = 0; |
43 | 1.06k | uint16_t flags = 0; |
44 | | |
45 | 1.06k | size_t utf16_string_size = 0; |
46 | 1.06k | size_t utf8_string_size = 0; |
47 | | |
48 | 1.06k | if( libfmapi_one_off_entry_identifier_initialize( |
49 | 1.06k | &one_off_entry_identifier, |
50 | 1.06k | &error ) == 1 |
51 | | /* TODO replace 1252 by codepage definition */ |
52 | 1.06k | && libfmapi_one_off_entry_identifier_copy_from_byte_stream( |
53 | 1.06k | one_off_entry_identifier, |
54 | 1.06k | data, |
55 | 1.06k | size, |
56 | 1.06k | 1252, |
57 | 1.06k | &error ) == 1 ) |
58 | 687 | { |
59 | 687 | libfmapi_one_off_entry_identifier_get_version( |
60 | 687 | one_off_entry_identifier, |
61 | 687 | &format_version, |
62 | 687 | &error ); |
63 | | |
64 | 687 | libfmapi_one_off_entry_identifier_get_flags( |
65 | 687 | one_off_entry_identifier, |
66 | 687 | &flags, |
67 | 687 | &error ); |
68 | | |
69 | | /* Retrieves the display name as UTF-16 string |
70 | | */ |
71 | 687 | if( libfmapi_one_off_entry_identifier_get_utf16_display_name_size( |
72 | 687 | one_off_entry_identifier, |
73 | 687 | &utf16_string_size, |
74 | 687 | &error ) == 1 |
75 | 642 | && ( utf16_string_size > 1 ) |
76 | 312 | && ( utf16_string_size <= 16384 ) ) |
77 | 286 | { |
78 | 286 | uint16_t *utf16_string = (uint16_t *) malloc( sizeof( uint16_t ) * utf16_string_size ); |
79 | | |
80 | 286 | if( utf16_string != NULL ) |
81 | 286 | { |
82 | 286 | libfmapi_one_off_entry_identifier_get_utf16_display_name( |
83 | 286 | one_off_entry_identifier, |
84 | 286 | utf16_string, |
85 | 286 | utf16_string_size - 1, |
86 | 286 | &error ); |
87 | | |
88 | 286 | libfmapi_one_off_entry_identifier_get_utf16_display_name( |
89 | 286 | one_off_entry_identifier, |
90 | 286 | utf16_string, |
91 | 286 | utf16_string_size, |
92 | 286 | &error ); |
93 | | |
94 | 286 | free( |
95 | 286 | utf16_string ); |
96 | 286 | } |
97 | 286 | } |
98 | | /* Retrieves the display name as UTF-8 string |
99 | | */ |
100 | 687 | if( libfmapi_one_off_entry_identifier_get_utf8_display_name_size( |
101 | 687 | one_off_entry_identifier, |
102 | 687 | &utf8_string_size, |
103 | 687 | &error ) == 1 |
104 | 642 | && ( utf8_string_size > 1 ) |
105 | 312 | && ( utf8_string_size <= 16384 ) ) |
106 | 266 | { |
107 | 266 | uint8_t *utf8_string = (uint8_t *) malloc( utf8_string_size ); |
108 | | |
109 | 266 | if( utf8_string != NULL ) |
110 | 266 | { |
111 | 266 | libfmapi_one_off_entry_identifier_get_utf8_display_name( |
112 | 266 | one_off_entry_identifier, |
113 | 266 | utf8_string, |
114 | 266 | utf8_string_size - 1, |
115 | 266 | &error ); |
116 | | |
117 | 266 | libfmapi_one_off_entry_identifier_get_utf8_display_name( |
118 | 266 | one_off_entry_identifier, |
119 | 266 | utf8_string, |
120 | 266 | utf8_string_size, |
121 | 266 | &error ); |
122 | | |
123 | 266 | free( |
124 | 266 | utf8_string ); |
125 | 266 | } |
126 | 266 | } |
127 | | /* Retrieves the address type as UTF-16 string |
128 | | */ |
129 | 687 | if( libfmapi_one_off_entry_identifier_get_utf16_address_type_size( |
130 | 687 | one_off_entry_identifier, |
131 | 687 | &utf16_string_size, |
132 | 687 | &error ) == 1 |
133 | 659 | && ( utf16_string_size > 1 ) |
134 | 253 | && ( utf16_string_size <= 16384 ) ) |
135 | 223 | { |
136 | 223 | uint16_t *utf16_string = (uint16_t *) malloc( sizeof( uint16_t ) * utf16_string_size ); |
137 | | |
138 | 223 | if( utf16_string != NULL ) |
139 | 223 | { |
140 | 223 | libfmapi_one_off_entry_identifier_get_utf16_address_type( |
141 | 223 | one_off_entry_identifier, |
142 | 223 | utf16_string, |
143 | 223 | utf16_string_size - 1, |
144 | 223 | &error ); |
145 | | |
146 | 223 | libfmapi_one_off_entry_identifier_get_utf16_address_type( |
147 | 223 | one_off_entry_identifier, |
148 | 223 | utf16_string, |
149 | 223 | utf16_string_size, |
150 | 223 | &error ); |
151 | | |
152 | 223 | free( |
153 | 223 | utf16_string ); |
154 | 223 | } |
155 | 223 | } |
156 | | /* Retrieves the address type as UTF-8 string |
157 | | */ |
158 | 687 | if( libfmapi_one_off_entry_identifier_get_utf8_address_type_size( |
159 | 687 | one_off_entry_identifier, |
160 | 687 | &utf8_string_size, |
161 | 687 | &error ) == 1 |
162 | 659 | && ( utf8_string_size > 1 ) |
163 | 253 | && ( utf8_string_size <= 16384 ) ) |
164 | 203 | { |
165 | 203 | uint8_t *utf8_string = (uint8_t *) malloc( utf8_string_size ); |
166 | | |
167 | 203 | if( utf8_string != NULL ) |
168 | 203 | { |
169 | 203 | libfmapi_one_off_entry_identifier_get_utf8_address_type( |
170 | 203 | one_off_entry_identifier, |
171 | 203 | utf8_string, |
172 | 203 | utf8_string_size - 1, |
173 | 203 | &error ); |
174 | | |
175 | 203 | libfmapi_one_off_entry_identifier_get_utf8_address_type( |
176 | 203 | one_off_entry_identifier, |
177 | 203 | utf8_string, |
178 | 203 | utf8_string_size, |
179 | 203 | &error ); |
180 | | |
181 | 203 | free( |
182 | 203 | utf8_string ); |
183 | 203 | } |
184 | 203 | } |
185 | | /* Retrieves the email address as UTF-16 string |
186 | | */ |
187 | 687 | if( libfmapi_one_off_entry_identifier_get_utf16_email_address_size( |
188 | 687 | one_off_entry_identifier, |
189 | 687 | &utf16_string_size, |
190 | 687 | &error ) == 1 |
191 | 667 | && ( utf16_string_size > 1 ) |
192 | 339 | && ( utf16_string_size <= 16384 ) ) |
193 | 310 | { |
194 | 310 | uint16_t *utf16_string = (uint16_t *) malloc( sizeof( uint16_t ) * utf16_string_size ); |
195 | | |
196 | 310 | if( utf16_string != NULL ) |
197 | 310 | { |
198 | 310 | libfmapi_one_off_entry_identifier_get_utf16_email_address( |
199 | 310 | one_off_entry_identifier, |
200 | 310 | utf16_string, |
201 | 310 | utf16_string_size - 1, |
202 | 310 | &error ); |
203 | | |
204 | 310 | libfmapi_one_off_entry_identifier_get_utf16_email_address( |
205 | 310 | one_off_entry_identifier, |
206 | 310 | utf16_string, |
207 | 310 | utf16_string_size, |
208 | 310 | &error ); |
209 | | |
210 | 310 | free( |
211 | 310 | utf16_string ); |
212 | 310 | } |
213 | 310 | } |
214 | | /* Retrieves the email address as UTF-8 string |
215 | | */ |
216 | 687 | if( libfmapi_one_off_entry_identifier_get_utf8_email_address_size( |
217 | 687 | one_off_entry_identifier, |
218 | 687 | &utf8_string_size, |
219 | 687 | &error ) == 1 |
220 | 667 | && ( utf8_string_size > 1 ) |
221 | 339 | && ( utf8_string_size <= 16384 ) ) |
222 | 297 | { |
223 | 297 | uint8_t *utf8_string = (uint8_t *) malloc( utf8_string_size ); |
224 | | |
225 | 297 | if( utf8_string != NULL ) |
226 | 297 | { |
227 | 297 | libfmapi_one_off_entry_identifier_get_utf8_email_address( |
228 | 297 | one_off_entry_identifier, |
229 | 297 | utf8_string, |
230 | 297 | utf8_string_size - 1, |
231 | 297 | &error ); |
232 | | |
233 | 297 | libfmapi_one_off_entry_identifier_get_utf8_email_address( |
234 | 297 | one_off_entry_identifier, |
235 | 297 | utf8_string, |
236 | 297 | utf8_string_size, |
237 | 297 | &error ); |
238 | | |
239 | 297 | free( |
240 | 297 | utf8_string ); |
241 | 297 | } |
242 | 297 | } |
243 | 687 | } |
244 | 1.06k | libfmapi_one_off_entry_identifier_free( |
245 | 1.06k | &one_off_entry_identifier, |
246 | 1.06k | &error ); |
247 | | |
248 | 1.06k | if( error != NULL ) |
249 | 1.00k | { |
250 | 1.00k | libfmapi_error_sprint( |
251 | 1.00k | error, |
252 | 1.00k | error_string, |
253 | 1.00k | sizeof( error_string ) ); |
254 | | |
255 | 1.00k | libfmapi_error_backtrace_sprint( |
256 | 1.00k | error, |
257 | 1.00k | error_string, |
258 | 1.00k | sizeof( error_string ) ); |
259 | 1.00k | } |
260 | 1.06k | libfmapi_error_free( |
261 | 1.06k | &error ); |
262 | | |
263 | 1.06k | return( 0 ); |
264 | 1.06k | } |
265 | | |
266 | | } /* extern "C" */ |