Skip to content

Commit 2980a18

Browse files
committed
Fix crash in validateaddress with -disablewallet
Fix a null pointer dereference in validateaddress with -disablewallet. Also add a regression testcase.
1 parent 4ee149a commit 2980a18

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

qa/pull-tester/rpc-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
'decodescript.py',
6969
'p2p-fullblocktest.py',
7070
'blockchain.py',
71+
'disablewallet.py',
7172
]
7273
testScriptsExt = [
7374
'bip65-cltv.py',

qa/rpc-tests/disablewallet.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python2
2+
# Copyright (c) 2014 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#
7+
# Exercise API with -disablewallet.
8+
#
9+
10+
from test_framework.test_framework import BitcoinTestFramework
11+
from test_framework.util import *
12+
13+
class DisableWalletTest (BitcoinTestFramework):
14+
15+
def setup_chain(self):
16+
print("Initializing test directory "+self.options.tmpdir)
17+
initialize_chain_clean(self.options.tmpdir, 1)
18+
19+
def setup_network(self, split=False):
20+
self.nodes = start_nodes(1, self.options.tmpdir, [['-disablewallet']])
21+
self.is_network_split = False
22+
self.sync_all()
23+
24+
def run_test (self):
25+
# Check regression: https://github.com/bitcoin/bitcoin/issues/6963#issuecomment-154548880
26+
x = self.nodes[0].validateaddress('3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy')
27+
assert(x['isvalid'] == False)
28+
x = self.nodes[0].validateaddress('mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ')
29+
assert(x['isvalid'] == True)
30+
31+
if __name__ == '__main__':
32+
DisableWalletTest ().main ()

src/rpcmisc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
117117
UniValue obj(UniValue::VOBJ);
118118
CPubKey vchPubKey;
119119
obj.push_back(Pair("isscript", false));
120-
if (pwalletMain->GetPubKey(keyID, vchPubKey)) {
120+
if (pwalletMain && pwalletMain->GetPubKey(keyID, vchPubKey)) {
121121
obj.push_back(Pair("pubkey", HexStr(vchPubKey)));
122122
obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed()));
123123
}
@@ -128,7 +128,7 @@ class DescribeAddressVisitor : public boost::static_visitor<UniValue>
128128
UniValue obj(UniValue::VOBJ);
129129
CScript subscript;
130130
obj.push_back(Pair("isscript", true));
131-
if (pwalletMain->GetCScript(scriptID, subscript)) {
131+
if (pwalletMain && pwalletMain->GetCScript(scriptID, subscript)) {
132132
std::vector<CTxDestination> addresses;
133133
txnouttype whichType;
134134
int nRequired;

0 commit comments

Comments
 (0)