Skip to content

Commit

Permalink
Return error when importmulti called with invalid address.
Browse files Browse the repository at this point in the history
Lack of error checking noticed by Alex Morcos <[email protected]>
  • Loading branch information
ryanofsky committed Feb 13, 2017
1 parent d978c41 commit 9acf25c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions qa/rpc-tests/importmulti.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ def run_test (self):
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")
Expand Down
3 changes: 3 additions & 0 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 9acf25c

Please sign in to comment.