diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-06-08 12:48:46 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-06-08 13:36:48 +0200 |
commit | 9c248e39f2807a7f89e555e99cc55cb2de1ad335 (patch) | |
tree | 23d98e7fdeec7350b6ff274775cce9ee91d5e13c /src/core_read.cpp | |
parent | 35e7f13f68f970d036606e111429ae34750c363a (diff) | |
parent | ac4e438229134595e949bfedb1f487c71fd45d24 (diff) |
Merge #10481: Decodehextx scripts sanity check
ac4e438 Sanity check transaction scripts in DecodeHexTx (Andrew Chow)
5b75c47 Add a valid opcode sanity check to CScript (Andrew Chow)
Tree-SHA512: a516e95c274c9d131123150c798cae8bed75925e8a4d59469967dd7f1d49f7f8161e26afb61024b821bd8dcdffdfd0d19b8dcad20b39b1106820326d8d56904d
Diffstat (limited to 'src/core_read.cpp')
-rw-r--r-- | src/core_read.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/core_read.cpp b/src/core_read.cpp index a8d667e3bc..463871d178 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -88,10 +88,32 @@ CScript ParseScript(const std::string& s) return result; } +// Check that all of the input and output scripts of a transaction contains valid opcodes +bool CheckTxScriptsSanity(const CMutableTransaction& tx) +{ + // Check input scripts for non-coinbase txs + if (!CTransaction(tx).IsCoinBase()) { + for (unsigned int i = 0; i < tx.vin.size(); i++) { + if (!tx.vin[i].scriptSig.HasValidOps() || tx.vin[i].scriptSig.size() > MAX_SCRIPT_SIZE) { + return false; + } + } + } + // Check output scripts + for (unsigned int i = 0; i < tx.vout.size(); i++) { + if (!tx.vout[i].scriptPubKey.HasValidOps() || tx.vout[i].scriptPubKey.size() > MAX_SCRIPT_SIZE) { + return false; + } + } + + return true; +} + bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTryNoWitness) { - if (!IsHex(strHexTx)) + if (!IsHex(strHexTx)) { return false; + } std::vector<unsigned char> txData(ParseHex(strHexTx)); @@ -99,7 +121,7 @@ bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTry CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS); try { ssData >> tx; - if (ssData.eof()) { + if (ssData.eof() && CheckTxScriptsSanity(tx)) { return true; } } @@ -111,8 +133,9 @@ bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx, bool fTry CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION); try { ssData >> tx; - if (!ssData.empty()) + if (!ssData.empty()) { return false; + } } catch (const std::exception&) { return false; |