aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-11-20 09:56:40 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2017-11-20 09:57:37 +0100
commita69cc077d9464898cefe4e75b0cd1880e66a2cf6 (patch)
tree66b608d97cdba7a6de04af8e9a3e2055ce66d67d
parenta81642c650cf6aa5b00fc9ef7d35941da5b32aa4 (diff)
parentf455bfd78abeffd9b63f4097ab796d4f2c46a220 (diff)
downloadbitcoin-a69cc077d9464898cefe4e75b0cd1880e66a2cf6.tar.xz
Merge #11662: [0.15] Sanity-check script sizes in bitcoin-tx
f455bfd Sanity-check script sizes in bitcoin-tx (Matt Corallo) Pull request description: Backport of #11554 Cleanly merges into 0.14 too if we care. Tree-SHA512: e8aff8bcde5925a73b2b9293f4782cdcf5ebc71a29001a592628b2d77e368db9905823fe7956c8e8b50ae942c77f64d48e6023a58f95b1457e106fca780308a3
-rw-r--r--src/bitcoin-tx.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp
index 0f2c19bd5d..25a1028536 100644
--- a/src/bitcoin-tx.cpp
+++ b/src/bitcoin-tx.cpp
@@ -389,6 +389,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);
@@ -451,10 +455,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());
}