/src/libfwevt/ossfuzz/manifest_fuzzer.cc
Line | Count | Source |
1 | | /* |
2 | | * OSS-Fuzz target for libfwevt manifest 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 | | #include <stdlib.h> |
26 | | |
27 | | /* Note that some of the OSS-Fuzz engines use C++ |
28 | | */ |
29 | | extern "C" { |
30 | | |
31 | | #include "ossfuzz_libfwevt.h" |
32 | | |
33 | | static const size_t max_string_size = 8 * 1024 * 1024; |
34 | | |
35 | | int LLVMFuzzerTestOneInput( |
36 | | const uint8_t *data, |
37 | | size_t size ) |
38 | 4.13k | { |
39 | 4.13k | libfwevt_channel_t *channel = NULL; |
40 | 4.13k | libfwevt_manifest_t *manifest = NULL; |
41 | 4.13k | libfwevt_provider_t *provider = NULL; |
42 | 4.13k | libfwevt_provider_t *provider_by_identifier = NULL; |
43 | 4.13k | libfwevt_template_item_t *item = NULL; |
44 | 4.13k | libfwevt_template_t *wevt_template = NULL; |
45 | 4.13k | uint8_t *utf8_name = NULL; |
46 | 4.13k | uint8_t input_data_type = 0; |
47 | 4.13k | size_t utf8_name_size = 0; |
48 | 4.13k | int number_of_channels = 0; |
49 | 4.13k | int number_of_items = 0; |
50 | 4.13k | int number_of_providers = 0; |
51 | 4.13k | int number_of_templates = 0; |
52 | | |
53 | 4.13k | if( libfwevt_manifest_initialize( |
54 | 4.13k | &manifest, |
55 | 4.13k | NULL ) != 1 ) |
56 | 0 | { |
57 | 0 | return( 0 ); |
58 | 0 | } |
59 | 4.13k | if( libfwevt_manifest_read( |
60 | 4.13k | manifest, |
61 | 4.13k | data, |
62 | 4.13k | size, |
63 | 4.13k | NULL ) != 1 ) |
64 | 3.04k | { |
65 | 3.04k | goto on_error_manifest; |
66 | 3.04k | } |
67 | 1.08k | if( libfwevt_manifest_get_number_of_providers( |
68 | 1.08k | manifest, |
69 | 1.08k | &number_of_providers, |
70 | 1.08k | NULL ) == 1 |
71 | 1.08k | && ( number_of_providers > 0 ) ) |
72 | 1.07k | { |
73 | 1.07k | if( libfwevt_manifest_get_provider_by_index( |
74 | 1.07k | manifest, |
75 | 1.07k | 0, |
76 | 1.07k | &provider, |
77 | 1.07k | NULL ) == 1 ) |
78 | 1.07k | { |
79 | 1.07k | if( libfwevt_provider_get_number_of_channels( |
80 | 1.07k | provider, |
81 | 1.07k | &number_of_channels, |
82 | 1.07k | NULL ) == 1 |
83 | 1.07k | && ( number_of_channels > 0 ) ) |
84 | 363 | { |
85 | 363 | if( libfwevt_provider_get_channel_by_index( |
86 | 363 | provider, |
87 | 363 | 0, |
88 | 363 | &channel, |
89 | 363 | NULL ) == 1 ) |
90 | 363 | { |
91 | 363 | if( libfwevt_channel_get_utf8_name_size( |
92 | 363 | channel, |
93 | 363 | &utf8_name_size, |
94 | 363 | NULL ) == 1 |
95 | 233 | && ( utf8_name_size > 0 ) |
96 | 231 | && ( utf8_name_size < max_string_size ) ) |
97 | 231 | { |
98 | 231 | utf8_name = (uint8_t *) malloc( utf8_name_size ); |
99 | | |
100 | 231 | if( utf8_name != NULL ) |
101 | 231 | { |
102 | 231 | libfwevt_channel_get_utf8_name( |
103 | 231 | channel, |
104 | 231 | utf8_name, |
105 | 231 | utf8_name_size, |
106 | 231 | NULL ); |
107 | 231 | free( utf8_name ); |
108 | | |
109 | 231 | utf8_name = NULL; |
110 | 231 | } |
111 | 231 | } |
112 | 363 | } |
113 | 363 | } |
114 | 1.07k | if( libfwevt_provider_get_number_of_templates( |
115 | 1.07k | provider, |
116 | 1.07k | &number_of_templates, |
117 | 1.07k | NULL ) == 1 |
118 | 1.07k | && ( number_of_templates > 0 ) ) |
119 | 112 | { |
120 | 112 | if( libfwevt_provider_get_template_by_index( |
121 | 112 | provider, |
122 | 112 | 0, |
123 | 112 | &wevt_template, |
124 | 112 | NULL ) == 1 ) |
125 | 112 | { |
126 | 112 | if( libfwevt_template_get_number_of_items( |
127 | 112 | wevt_template, |
128 | 112 | &number_of_items, |
129 | 112 | NULL ) == 1 |
130 | 112 | && ( number_of_items > 0 ) ) |
131 | 60 | { |
132 | 60 | if( libfwevt_template_get_item_by_index( |
133 | 60 | wevt_template, |
134 | 60 | 0, |
135 | 60 | &item, |
136 | 60 | NULL ) == 1 ) |
137 | 60 | { |
138 | 60 | libfwevt_template_item_get_input_data_type( |
139 | 60 | item, |
140 | 60 | &input_data_type, |
141 | 60 | NULL ); |
142 | | |
143 | 60 | if( libfwevt_template_item_get_utf8_name_size( |
144 | 60 | item, |
145 | 60 | &utf8_name_size, |
146 | 60 | NULL ) == 1 |
147 | 26 | && ( utf8_name_size > 0 ) |
148 | 25 | && ( utf8_name_size < max_string_size ) ) |
149 | 25 | { |
150 | 25 | utf8_name = (uint8_t *) malloc( utf8_name_size ); |
151 | | |
152 | 25 | if( utf8_name != NULL ) |
153 | 25 | { |
154 | 25 | libfwevt_template_item_get_utf8_name( |
155 | 25 | item, |
156 | 25 | utf8_name, |
157 | 25 | utf8_name_size, |
158 | 25 | NULL ); |
159 | 25 | free( utf8_name ); |
160 | | |
161 | 25 | utf8_name = NULL; |
162 | 25 | } |
163 | 25 | } |
164 | 60 | } |
165 | 60 | } |
166 | 112 | } |
167 | 112 | } |
168 | 1.07k | } |
169 | 1.07k | } |
170 | | /* Exercise the provider identifier (GUID) lookup using the |
171 | | * first 16 bytes of the input as identifier |
172 | | */ |
173 | 1.08k | if( size >= 16 ) |
174 | 1.08k | { |
175 | 1.08k | libfwevt_manifest_get_provider_by_identifier( |
176 | 1.08k | manifest, |
177 | 1.08k | data, |
178 | 1.08k | 16, |
179 | 1.08k | &provider_by_identifier, |
180 | 1.08k | NULL ); |
181 | 1.08k | } |
182 | 1.08k | goto on_error_manifest; |
183 | | |
184 | 4.13k | on_error_manifest: |
185 | 4.13k | if( manifest != NULL ) |
186 | 4.13k | { |
187 | 4.13k | libfwevt_manifest_free( |
188 | 4.13k | &manifest, |
189 | | NULL ); |
190 | 4.13k | } |
191 | 4.13k | return( 0 ); |
192 | 4.13k | } |
193 | | |
194 | | } /* extern "C" */ |