aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Todd <pete@petertodd.org>2014-03-10 22:43:15 -0400
committerWladimir J. van der Laan <laanwj@gmail.com>2014-08-18 15:34:29 +0200
commitfd0c4606bc89ab974e39a98fd42f4a28eb874062 (patch)
treef0f5184d4f0a36e16f6a23d4771caee01e345638
parent4b57c5b3c7f425a8cd122491c9dd69fe52dd3715 (diff)
downloadbitcoin-fd0c4606bc89ab974e39a98fd42f4a28eb874062.tar.xz
Check redeemScript size does not exceed 520 byte limit
redeemScripts >520bytes can't be spent due to the MAX_SCRIPT_ELEMENT_SIZE limit; previously the addmultisigaddress and createmultisig RPC calls would let you violate that limit unknowingly. Also made the wallet code itself check the redeemScript prior to adding it to the wallet, which in the (rare) instance that a user has added an invalid oversized redeemScript to their wallet causes an error on startup. The affected key isn't added to the wallet; other keys are unaffected.
-rw-r--r--src/keystore.cpp3
-rw-r--r--src/rpcmisc.cpp9
-rw-r--r--src/rpcwallet.cpp4
3 files changed, 12 insertions, 4 deletions
diff --git a/src/keystore.cpp b/src/keystore.cpp
index 46402ea25b..594e0c61da 100644
--- a/src/keystore.cpp
+++ b/src/keystore.cpp
@@ -33,6 +33,9 @@ bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey)
bool CBasicKeyStore::AddCScript(const CScript& redeemScript)
{
+ if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
+ return error("CBasicKeyStore::AddCScript() : redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
+
LOCK(cs_KeyStore);
mapScripts[redeemScript.GetID()] = redeemScript;
return true;
diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp
index 5ccdffdebe..27d6d61a36 100644
--- a/src/rpcmisc.cpp
+++ b/src/rpcmisc.cpp
@@ -176,7 +176,7 @@ Value validateaddress(const Array& params, bool fHelp)
//
// Used by addmultisigaddress / createmultisig:
//
-CScript _createmultisig(const Array& params)
+CScript _createmultisig_redeemScript(const Array& params)
{
int nRequired = params[0].get_int();
const Array& keys = params[1].get_array();
@@ -228,6 +228,11 @@ CScript _createmultisig(const Array& params)
}
CScript result;
result.SetMultisig(nRequired, pubkeys);
+
+ if (result.size() > MAX_SCRIPT_ELEMENT_SIZE)
+ throw runtime_error(
+ strprintf("redeemScript exceeds size limit: %d > %d", result.size(), MAX_SCRIPT_ELEMENT_SIZE));
+
return result;
}
@@ -263,7 +268,7 @@ Value createmultisig(const Array& params, bool fHelp)
}
// Construct using pay-to-script-hash:
- CScript inner = _createmultisig(params);
+ CScript inner = _createmultisig_redeemScript(params);
CScriptID innerID = inner.GetID();
CBitcoinAddress address(innerID);
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index 151a47468f..e3b35dbb04 100644
--- a/src/rpcwallet.cpp
+++ b/src/rpcwallet.cpp
@@ -871,7 +871,7 @@ Value sendmany(const Array& params, bool fHelp)
}
// Defined in rpcmisc.cpp
-extern CScript _createmultisig(const Array& params);
+extern CScript _createmultisig_redeemScript(const Array& params);
Value addmultisigaddress(const Array& params, bool fHelp)
{
@@ -908,7 +908,7 @@ Value addmultisigaddress(const Array& params, bool fHelp)
strAccount = AccountFromValue(params[2]);
// Construct using pay-to-script-hash:
- CScript inner = _createmultisig(params);
+ CScript inner = _createmultisig_redeemScript(params);
CScriptID innerID = inner.GetID();
pwalletMain->AddCScript(inner);