diff options
author | Wladimir J. van der Laan <laanwj@protonmail.com> | 2020-01-20 20:36:21 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@protonmail.com> | 2020-01-20 20:38:57 +0100 |
commit | daae6403d8bd1d03b108d0517bd74e3197e315a8 (patch) | |
tree | ab845a09c280abeb9f36e0547fc1768cd87adf77 /src/test/fuzz | |
parent | 5d2ff75e207021467160aec5986d7d6d54a2b708 (diff) | |
parent | 3f95fb085e73b5537dda6d7258bfdab72d695fa9 (diff) |
Merge #17777: tests: Add fuzzing harness for DecodeHexTx(…)
3f95fb085e73b5537dda6d7258bfdab72d695fa9 build: Sort fuzzing harnesses to avoid future merge conflicts (practicalswift)
bcad0144eff3192cb54f65fa7737be53e03f8b0f tests: Add fuzzing harness for DecodeHexTx(...) (practicalswift)
Pull request description:
Add fuzzing harness for `DecodeHexTx(…)`.
To test this PR:
```
$ make distclean
$ ./autogen.sh
$ CC=clang CXX=clang++ ./configure --enable-fuzz \
--with-sanitizers=address,fuzzer,undefined
$ make
$ src/test/fuzz/decode_tx
…
```
ACKs for top commit:
jonatack:
ACK 3f95fb0
Tree-SHA512: 0f476d0cc26f1e03812664373118754042074bdab6c1e3a57c721f863feb82ca2986cceeaceb03192d893b9aa1d4ad8a5fb4c74824b9547fd8567805931a9ebd
Diffstat (limited to 'src/test/fuzz')
-rw-r--r-- | src/test/fuzz/decode_tx.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/fuzz/decode_tx.cpp b/src/test/fuzz/decode_tx.cpp new file mode 100644 index 0000000000..09c4ff05df --- /dev/null +++ b/src/test/fuzz/decode_tx.cpp @@ -0,0 +1,31 @@ +// Copyright (c) 2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include <core_io.h> +#include <primitives/transaction.h> +#include <test/fuzz/fuzz.h> +#include <util/strencodings.h> + +#include <cassert> +#include <cstdint> +#include <string> +#include <vector> + +void test_one_input(const std::vector<uint8_t>& buffer) +{ + const std::string tx_hex = HexStr(std::string{buffer.begin(), buffer.end()}); + CMutableTransaction mtx; + const bool result_none = DecodeHexTx(mtx, tx_hex, false, false); + const bool result_try_witness = DecodeHexTx(mtx, tx_hex, false, true); + const bool result_try_witness_and_maybe_no_witness = DecodeHexTx(mtx, tx_hex, true, true); + const bool result_try_no_witness = DecodeHexTx(mtx, tx_hex, true, false); + assert(!result_none); + if (result_try_witness_and_maybe_no_witness) { + assert(result_try_no_witness || result_try_witness); + } + // if (result_try_no_witness) { // Uncomment when https://github.com/bitcoin/bitcoin/pull/17775 is merged + if (result_try_witness) { // Remove stop-gap when https://github.com/bitcoin/bitcoin/pull/17775 is merged + assert(result_try_witness_and_maybe_no_witness); + } +} |