diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2017-02-13 17:54:51 -0500 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2017-02-13 17:54:51 -0500 |
commit | 9acf25cc013c013ee5b07dba7b1319b7c5a7b6a4 (patch) | |
tree | 4565391074de7304a344e97c1418ada6ff11fc38 | |
parent | d978c41e1ec4fcf2c4d096f09af035f9e8a7ad81 (diff) |
Return error when importmulti called with invalid address.
Lack of error checking noticed by Alex Morcos <morcos@chaincode.com>
-rwxr-xr-x | qa/rpc-tests/importmulti.py | 10 | ||||
-rw-r--r-- | src/wallet/rpcdump.cpp | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/qa/rpc-tests/importmulti.py b/qa/rpc-tests/importmulti.py index e100a3af9d..43964610e5 100755 --- a/qa/rpc-tests/importmulti.py +++ b/qa/rpc-tests/importmulti.py @@ -59,6 +59,16 @@ class ImportMultiTest (BitcoinTestFramework): assert_equal(address_assert['iswatchonly'], True) assert_equal(address_assert['ismine'], False) + print("Should not import an invalid address") + result = self.nodes[1].importmulti([{ + "scriptPubKey": { + "address": "not valid address", + }, + "timestamp": "now", + }]) + assert_equal(result[0]['success'], False) + assert_equal(result[0]['error']['code'], -5) + assert_equal(result[0]['error']['message'], 'Invalid address') # ScriptPubKey + internal print("Should import a scriptPubKey with internal flag") diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 7d4ed70ed9..738643eb01 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -671,6 +671,9 @@ UniValue processImport(const UniValue& data) { if (!isScript) { address = CBitcoinAddress(output); + if (!address.IsValid()) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); + } script = GetScriptForDestination(address.Get()); } else { if (!IsHex(output)) { |