diff options
author | Matt Corallo <git@bluematt.me> | 2017-10-24 14:11:21 -0400 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2017-11-11 14:24:38 +0000 |
commit | f455bfd78abeffd9b63f4097ab796d4f2c46a220 (patch) | |
tree | 50c21c221d1f1e15ecef24125b27647fd4f26af5 | |
parent | 9828f9a9962c1bee5c343847030b9cfd87a40a5e (diff) | |
download | bitcoin-f455bfd78abeffd9b63f4097ab796d4f2c46a220.tar.xz |
Sanity-check script sizes in bitcoin-tx
Github-Pull: #11554
Rebased-From: a6f33ea77d3a48f06b5c7cfcc20553c9a88d429a
-rw-r--r-- | src/bitcoin-tx.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 3c3646523a..495ee5df02 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -355,6 +355,10 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s scriptPubKey = GetScriptForWitness(scriptPubKey); } if (bScriptHash) { + if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) { + throw std::runtime_error(strprintf( + "redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE)); + } // Get the address for the redeem script, then call // GetScriptForDestination() to construct a P2SH scriptPubKey. CBitcoinAddress addr(scriptPubKey); @@ -417,10 +421,19 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str bScriptHash = (flags.find("S") != std::string::npos); } + if (scriptPubKey.size() > MAX_SCRIPT_SIZE) { + throw std::runtime_error(strprintf( + "script exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_SIZE)); + } + if (bSegWit) { scriptPubKey = GetScriptForWitness(scriptPubKey); } if (bScriptHash) { + if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) { + throw std::runtime_error(strprintf( + "redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE)); + } CBitcoinAddress addr(scriptPubKey); scriptPubKey = GetScriptForDestination(addr.Get()); } |