1 // Copyright (c) 2009-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #if defined(HAVE_CONFIG_H)
6 #include "config/bitcoin-config.h"
9 #include "consensus/merkle.h"
10 #include "primitives/block.h"
11 #include "script/script.h"
15 #include "compressor.h"
31 CTRANSACTION_DESERIALIZE
,
32 CBLOCKLOCATOR_DESERIALIZE
,
35 CBLOCKHEADER_DESERIALIZE
,
36 CBANENTRY_DESERIALIZE
,
38 CBLOCKUNDO_DESERIALIZE
,
42 CMESSAGEHEADER_DESERIALIZE
,
45 CBLOOMFILTER_DESERIALIZE
,
46 CDISKBLOCKINDEX_DESERIALIZE
,
47 CTXOUTCOMPRESSOR_DESERIALIZE
,
51 bool read_stdin(std::vector
<char> &data
) {
54 while((length
= read(STDIN_FILENO
, buffer
, 1024)) > 0) {
55 data
.insert(data
.end(), buffer
, buffer
+length
);
57 if (data
.size() > (1<<20)) return false;
64 std::vector
<char> buffer
;
65 if (!read_stdin(buffer
)) return 0;
67 if (buffer
.size() < sizeof(uint32_t)) return 0;
69 uint32_t test_id
= 0xffffffff;
70 memcpy(&test_id
, buffer
.data(), sizeof(uint32_t));
71 buffer
.erase(buffer
.begin(), buffer
.begin() + sizeof(uint32_t));
73 if (test_id
>= TEST_ID_END
) return 0;
75 CDataStream
ds(buffer
, SER_NETWORK
, INIT_PROTO_VERSION
);
79 ds
.SetVersion(nVersion
);
80 } catch (const std::ios_base::failure
& e
) {
85 case CBLOCK_DESERIALIZE
:
91 } catch (const std::ios_base::failure
& e
) {return 0;}
94 case CTRANSACTION_DESERIALIZE
:
98 CTransaction
tx(deserialize
, ds
);
99 } catch (const std::ios_base::failure
& e
) {return 0;}
102 case CBLOCKLOCATOR_DESERIALIZE
:
108 } catch (const std::ios_base::failure
& e
) {return 0;}
111 case CBLOCKMERKLEROOT
:
118 BlockMerkleRoot(block
, &mutated
);
119 } catch (const std::ios_base::failure
& e
) {return 0;}
122 case CADDRMAN_DESERIALIZE
:
128 } catch (const std::ios_base::failure
& e
) {return 0;}
131 case CBLOCKHEADER_DESERIALIZE
:
137 } catch (const std::ios_base::failure
& e
) {return 0;}
140 case CBANENTRY_DESERIALIZE
:
146 } catch (const std::ios_base::failure
& e
) {return 0;}
149 case CTXUNDO_DESERIALIZE
:
155 } catch (const std::ios_base::failure
& e
) {return 0;}
158 case CBLOCKUNDO_DESERIALIZE
:
164 } catch (const std::ios_base::failure
& e
) {return 0;}
167 case CCOINS_DESERIALIZE
:
173 } catch (const std::ios_base::failure
& e
) {return 0;}
176 case CNETADDR_DESERIALIZE
:
182 } catch (const std::ios_base::failure
& e
) {return 0;}
185 case CSERVICE_DESERIALIZE
:
191 } catch (const std::ios_base::failure
& e
) {return 0;}
194 case CMESSAGEHEADER_DESERIALIZE
:
196 CMessageHeader::MessageStartChars pchMessageStart
= {0x00, 0x00, 0x00, 0x00};
199 CMessageHeader
mh(pchMessageStart
);
201 if (!mh
.IsValid(pchMessageStart
)) {return 0;}
202 } catch (const std::ios_base::failure
& e
) {return 0;}
205 case CADDRESS_DESERIALIZE
:
211 } catch (const std::ios_base::failure
& e
) {return 0;}
214 case CINV_DESERIALIZE
:
220 } catch (const std::ios_base::failure
& e
) {return 0;}
223 case CBLOOMFILTER_DESERIALIZE
:
229 } catch (const std::ios_base::failure
& e
) {return 0;}
232 case CDISKBLOCKINDEX_DESERIALIZE
:
238 } catch (const std::ios_base::failure
& e
) {return 0;}
241 case CTXOUTCOMPRESSOR_DESERIALIZE
:
244 CTxOutCompressor
toc(to
);
248 } catch (const std::ios_base::failure
& e
) {return 0;}
258 int main(int argc
, char **argv
)
260 ECCVerifyHandle globalVerifyHandle
;
262 // Enable AFL deferred forkserver mode. Requires compilation using
263 // afl-clang-fast++. See fuzzing.md for details.
268 // Enable AFL persistent mode. Requires compilation using afl-clang-fast++.
269 // See fuzzing.md for details.
270 while (__AFL_LOOP(1000)) {