@@ -47,33 +47,35 @@ enum TEST_ID {
47
47
TEST_ID_END
48
48
};
49
49
50
- bool read_stdin (std::vector<uint8_t > &data) {
50
+ static bool read_stdin (std::vector<uint8_t >& data)
51
+ {
51
52
uint8_t buffer[1024 ];
52
- ssize_t length= 0 ;
53
- while ((length = read (STDIN_FILENO, buffer, 1024 )) > 0 ) {
54
- data.insert (data.end (), buffer, buffer+ length);
53
+ ssize_t length = 0 ;
54
+ while ((length = read (STDIN_FILENO, buffer, 1024 )) > 0 ) {
55
+ data.insert (data.end (), buffer, buffer + length);
55
56
56
- if (data.size () > (1 << 20 )) return false ;
57
+ if (data.size () > (1 << 20 )) return false ;
57
58
}
58
- return length== 0 ;
59
+ return length == 0 ;
59
60
}
60
61
61
- int test_one_input (std::vector<uint8_t > buffer) {
62
- if (buffer.size () < sizeof (uint32_t )) return 0 ;
62
+ void test_one_input (std::vector<uint8_t > buffer)
63
+ {
64
+ if (buffer.size () < sizeof (uint32_t )) return ;
63
65
64
66
uint32_t test_id = 0xffffffff ;
65
67
memcpy (&test_id, &buffer[0 ], sizeof (uint32_t ));
66
68
buffer.erase (buffer.begin (), buffer.begin () + sizeof (uint32_t ));
67
69
68
- if (test_id >= TEST_ID_END) return 0 ;
70
+ if (test_id >= TEST_ID_END) return ;
69
71
70
72
CDataStream ds (buffer, SER_NETWORK, INIT_PROTO_VERSION);
71
73
try {
72
74
int nVersion;
73
75
ds >> nVersion;
74
76
ds.SetVersion (nVersion);
75
77
} catch (const std::ios_base::failure& e) {
76
- return 0 ;
78
+ return ;
77
79
}
78
80
79
81
switch (test_id) {
@@ -83,15 +85,15 @@ int test_one_input(std::vector<uint8_t> buffer) {
83
85
{
84
86
CBlock block;
85
87
ds >> block;
86
- } catch (const std::ios_base::failure& e) {return 0 ;}
88
+ } catch (const std::ios_base::failure& e) {return ;}
87
89
break ;
88
90
}
89
91
case CTRANSACTION_DESERIALIZE:
90
92
{
91
93
try
92
94
{
93
95
CTransaction tx (deserialize, ds);
94
- } catch (const std::ios_base::failure& e) {return 0 ;}
96
+ } catch (const std::ios_base::failure& e) {return ;}
95
97
break ;
96
98
}
97
99
case CBLOCKLOCATOR_DESERIALIZE:
@@ -100,7 +102,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
100
102
{
101
103
CBlockLocator bl;
102
104
ds >> bl;
103
- } catch (const std::ios_base::failure& e) {return 0 ;}
105
+ } catch (const std::ios_base::failure& e) {return ;}
104
106
break ;
105
107
}
106
108
case CBLOCKMERKLEROOT:
@@ -111,7 +113,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
111
113
ds >> block;
112
114
bool mutated;
113
115
BlockMerkleRoot (block, &mutated);
114
- } catch (const std::ios_base::failure& e) {return 0 ;}
116
+ } catch (const std::ios_base::failure& e) {return ;}
115
117
break ;
116
118
}
117
119
case CADDRMAN_DESERIALIZE:
@@ -120,7 +122,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
120
122
{
121
123
CAddrMan am;
122
124
ds >> am;
123
- } catch (const std::ios_base::failure& e) {return 0 ;}
125
+ } catch (const std::ios_base::failure& e) {return ;}
124
126
break ;
125
127
}
126
128
case CBLOCKHEADER_DESERIALIZE:
@@ -129,7 +131,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
129
131
{
130
132
CBlockHeader bh;
131
133
ds >> bh;
132
- } catch (const std::ios_base::failure& e) {return 0 ;}
134
+ } catch (const std::ios_base::failure& e) {return ;}
133
135
break ;
134
136
}
135
137
case CBANENTRY_DESERIALIZE:
@@ -138,7 +140,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
138
140
{
139
141
CBanEntry be;
140
142
ds >> be;
141
- } catch (const std::ios_base::failure& e) {return 0 ;}
143
+ } catch (const std::ios_base::failure& e) {return ;}
142
144
break ;
143
145
}
144
146
case CTXUNDO_DESERIALIZE:
@@ -147,7 +149,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
147
149
{
148
150
CTxUndo tu;
149
151
ds >> tu;
150
- } catch (const std::ios_base::failure& e) {return 0 ;}
152
+ } catch (const std::ios_base::failure& e) {return ;}
151
153
break ;
152
154
}
153
155
case CBLOCKUNDO_DESERIALIZE:
@@ -156,16 +158,16 @@ int test_one_input(std::vector<uint8_t> buffer) {
156
158
{
157
159
CBlockUndo bu;
158
160
ds >> bu;
159
- } catch (const std::ios_base::failure& e) {return 0 ;}
161
+ } catch (const std::ios_base::failure& e) {return ;}
160
162
break ;
161
163
}
162
164
case CCOINS_DESERIALIZE:
163
165
{
164
166
try
165
167
{
166
- Coin block ;
167
- ds >> block ;
168
- } catch (const std::ios_base::failure& e) {return 0 ;}
168
+ Coin coin ;
169
+ ds >> coin ;
170
+ } catch (const std::ios_base::failure& e) {return ;}
169
171
break ;
170
172
}
171
173
case CNETADDR_DESERIALIZE:
@@ -174,7 +176,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
174
176
{
175
177
CNetAddr na;
176
178
ds >> na;
177
- } catch (const std::ios_base::failure& e) {return 0 ;}
179
+ } catch (const std::ios_base::failure& e) {return ;}
178
180
break ;
179
181
}
180
182
case CSERVICE_DESERIALIZE:
@@ -183,7 +185,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
183
185
{
184
186
CService s;
185
187
ds >> s;
186
- } catch (const std::ios_base::failure& e) {return 0 ;}
188
+ } catch (const std::ios_base::failure& e) {return ;}
187
189
break ;
188
190
}
189
191
case CMESSAGEHEADER_DESERIALIZE:
@@ -193,8 +195,8 @@ int test_one_input(std::vector<uint8_t> buffer) {
193
195
{
194
196
CMessageHeader mh (pchMessageStart);
195
197
ds >> mh;
196
- if (!mh.IsValid (pchMessageStart)) {return 0 ;}
197
- } catch (const std::ios_base::failure& e) {return 0 ;}
198
+ if (!mh.IsValid (pchMessageStart)) {return ;}
199
+ } catch (const std::ios_base::failure& e) {return ;}
198
200
break ;
199
201
}
200
202
case CADDRESS_DESERIALIZE:
@@ -203,7 +205,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
203
205
{
204
206
CAddress a;
205
207
ds >> a;
206
- } catch (const std::ios_base::failure& e) {return 0 ;}
208
+ } catch (const std::ios_base::failure& e) {return ;}
207
209
break ;
208
210
}
209
211
case CINV_DESERIALIZE:
@@ -212,7 +214,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
212
214
{
213
215
CInv i;
214
216
ds >> i;
215
- } catch (const std::ios_base::failure& e) {return 0 ;}
217
+ } catch (const std::ios_base::failure& e) {return ;}
216
218
break ;
217
219
}
218
220
case CBLOOMFILTER_DESERIALIZE:
@@ -221,7 +223,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
221
223
{
222
224
CBloomFilter bf;
223
225
ds >> bf;
224
- } catch (const std::ios_base::failure& e) {return 0 ;}
226
+ } catch (const std::ios_base::failure& e) {return ;}
225
227
break ;
226
228
}
227
229
case CDISKBLOCKINDEX_DESERIALIZE:
@@ -230,7 +232,7 @@ int test_one_input(std::vector<uint8_t> buffer) {
230
232
{
231
233
CDiskBlockIndex dbi;
232
234
ds >> dbi;
233
- } catch (const std::ios_base::failure& e) {return 0 ;}
235
+ } catch (const std::ios_base::failure& e) {return ;}
234
236
break ;
235
237
}
236
238
case CTXOUTCOMPRESSOR_DESERIALIZE:
@@ -240,14 +242,14 @@ int test_one_input(std::vector<uint8_t> buffer) {
240
242
try
241
243
{
242
244
ds >> toc;
243
- } catch (const std::ios_base::failure& e) {return 0 ;}
245
+ } catch (const std::ios_base::failure& e) {return ;}
244
246
245
247
break ;
246
248
}
247
249
default :
248
- return 0 ;
250
+ return ;
249
251
}
250
- return 0 ;
252
+ return ;
251
253
}
252
254
253
255
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
@@ -257,13 +259,15 @@ void initialize() {
257
259
}
258
260
259
261
// This function is used by libFuzzer
260
- extern " C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) {
262
+ extern " C" int LLVMFuzzerTestOneInput (const uint8_t * data, size_t size)
263
+ {
261
264
test_one_input (std::vector<uint8_t >(data, data + size));
262
265
return 0 ;
263
266
}
264
267
265
268
// This function is used by libFuzzer
266
- extern " C" int LLVMFuzzerInitialize (int *argc, char ***argv) {
269
+ extern " C" int LLVMFuzzerInitialize (int * argc, char *** argv)
270
+ {
267
271
initialize ();
268
272
return 0 ;
269
273
}
@@ -286,20 +290,18 @@ int main(int argc, char **argv)
286
290
#ifdef __AFL_LOOP
287
291
// Enable AFL persistent mode. Requires compilation using afl-clang-fast++.
288
292
// See fuzzing.md for details.
289
- int ret = 0 ;
290
293
while (__AFL_LOOP (1000 )) {
291
294
std::vector<uint8_t > buffer;
292
295
if (!read_stdin (buffer)) {
293
296
continue ;
294
297
}
295
- ret = test_one_input (buffer);
298
+ test_one_input (buffer);
296
299
}
297
- return ret;
298
300
#else
299
301
std::vector<uint8_t > buffer;
300
302
if (!read_stdin (buffer)) {
301
303
return 0 ;
302
304
}
303
- return test_one_input (buffer);
305
+ test_one_input (buffer);
304
306
#endif
305
307
}
0 commit comments