Skip to content

Commit 9acf25c

Browse files
committed
Return error when importmulti called with invalid address.
Lack of error checking noticed by Alex Morcos <[email protected]>
1 parent d978c41 commit 9acf25c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

qa/rpc-tests/importmulti.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ def run_test (self):
5959
assert_equal(address_assert['iswatchonly'], True)
6060
assert_equal(address_assert['ismine'], False)
6161

62+
print("Should not import an invalid address")
63+
result = self.nodes[1].importmulti([{
64+
"scriptPubKey": {
65+
"address": "not valid address",
66+
},
67+
"timestamp": "now",
68+
}])
69+
assert_equal(result[0]['success'], False)
70+
assert_equal(result[0]['error']['code'], -5)
71+
assert_equal(result[0]['error']['message'], 'Invalid address')
6272

6373
# ScriptPubKey + internal
6474
print("Should import a scriptPubKey with internal flag")

src/wallet/rpcdump.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ UniValue processImport(const UniValue& data) {
671671

672672
if (!isScript) {
673673
address = CBitcoinAddress(output);
674+
if (!address.IsValid()) {
675+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
676+
}
674677
script = GetScriptForDestination(address.Get());
675678
} else {
676679
if (!IsHex(output)) {

0 commit comments

Comments
 (0)