Add check for valid keys in importprivkey

The base58 armoring was checked, but not the resulting private key,
which could be out of range. Fix this by adding a check.

Conflicts:
	src/rpcdump.cpp

Conflicts:
	src/rpcdump.cpp

Rebased-from: b403ab80ab39d41a6f965479cdf878cd8e58a399 0.8.x
This commit is contained in:
Wladimir J. van der Laan 2014-01-28 09:38:10 +01:00 committed by Warren Togami
parent 56646670e1
commit 7e1d5ca894

View File

@ -54,11 +54,13 @@ Value importprivkey(const Array& params, bool fHelp)
CBitcoinSecret vchSecret;
bool fGood = vchSecret.SetString(strSecret);
if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
CKey key = vchSecret.GetKey();
CPubKey pubkey = key.GetPubKey();
CKeyID vchAddress = pubkey.GetID();
if (!key.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Private key outside allowed range");
{
LOCK2(cs_main, pwalletMain->cs_wallet);