Skip to content

Commit 569a11f

Browse files
MarcoFalkecodablock
authored andcommitted
Merge bitcoin#11554: Sanity-check script sizes in bitcoin-tx
a6f33ea Sanity-check script sizes in bitcoin-tx (Matt Corallo) Pull request description: Tree-SHA512: bb8ecb628763af23816ab085758f6140920a6ff05dcb298129c2bbe584a02a759c700a05740eca77023292c98a5658b2a608fa27d5a948d183f87ed9ab827952
1 parent 7919c96 commit 569a11f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/dash-tx.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,10 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
351351
CScript scriptPubKey = GetScriptForMultisig(required, pubkeys);
352352

353353
if (bScriptHash) {
354-
// Get the address for the redeem script, then call
354+
if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
355+
throw std::runtime_error(strprintf(
356+
"redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
357+
}
355358
// GetScriptForDestination() to construct a P2SH scriptPubKey.
356359
CBitcoinAddress addr(scriptPubKey);
357360
scriptPubKey = GetScriptForDestination(addr.Get());
@@ -411,9 +414,18 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str
411414
bScriptHash = (flags.find("S") != std::string::npos);
412415
}
413416

417+
if (scriptPubKey.size() > MAX_SCRIPT_SIZE) {
418+
throw std::runtime_error(strprintf(
419+
"script exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_SIZE));
420+
}
421+
414422
if (bScriptHash) {
415-
CBitcoinAddress addr(scriptPubKey);
416-
scriptPubKey = GetScriptForDestination(addr.Get());
423+
if (scriptPubKey.size() > MAX_SCRIPT_ELEMENT_SIZE) {
424+
throw std::runtime_error(strprintf(
425+
"redeemScript exceeds size limit: %d > %d", scriptPubKey.size(), MAX_SCRIPT_ELEMENT_SIZE));
426+
}
427+
CBitcoinAddress addr(scriptPubKey);
428+
scriptPubKey = GetScriptForDestination(addr.Get());
417429
}
418430

419431
// construct TxOut, append to transaction output list

0 commit comments

Comments
 (0)