Skip to content

Commit 395b537

Browse files
laanwjPastaPastaPasta
authored andcommitted
Merge bitcoin#9774: Enable host lookups for -proxy and -onion parameters
f36bdf0 Enable host lookups for -proxy and -onion parameters (Johnathan Corgan) Tree-SHA512: 40f5ef3954721333e58d34653874d9f6ac5426c817762d132838f3b6f968ca5ca05aa56d02fd742cb5a8dc040f1a28dad6d54f667342eceba62fb2af18b58fc0
1 parent 2c3dde7 commit 395b537

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/init.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -1561,16 +1561,23 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
15611561
}
15621562
}
15631563

1564+
// Check for host lookup allowed before parsing any network related parameters
1565+
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
1566+
15641567
bool proxyRandomize = GetBoolArg("-proxyrandomize", DEFAULT_PROXYRANDOMIZE);
15651568
// -proxy sets a proxy for all outgoing network traffic
15661569
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
15671570
std::string proxyArg = GetArg("-proxy", "");
15681571
SetLimited(NET_TOR);
15691572
if (proxyArg != "" && proxyArg != "0") {
1570-
CService resolved(LookupNumeric(proxyArg.c_str(), 9050));
1571-
proxyType addrProxy = proxyType(resolved, proxyRandomize);
1573+
CService proxyAddr;
1574+
if (!Lookup(proxyArg.c_str(), proxyAddr, 9050, fNameLookup)) {
1575+
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
1576+
}
1577+
1578+
proxyType addrProxy = proxyType(proxyAddr, proxyRandomize);
15721579
if (!addrProxy.IsValid())
1573-
return InitError(strprintf(_("Invalid -proxy address: '%s'"), proxyArg));
1580+
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
15741581

15751582
SetProxy(NET_IPV4, addrProxy);
15761583
SetProxy(NET_IPV6, addrProxy);
@@ -1587,10 +1594,13 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
15871594
if (onionArg == "0") { // Handle -noonion/-onion=0
15881595
SetLimited(NET_TOR); // set onions as unreachable
15891596
} else {
1590-
CService resolved(LookupNumeric(onionArg.c_str(), 9050));
1591-
proxyType addrOnion = proxyType(resolved, proxyRandomize);
1597+
CService onionProxy;
1598+
if (!Lookup(onionArg.c_str(), onionProxy, 9050, fNameLookup)) {
1599+
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
1600+
}
1601+
proxyType addrOnion = proxyType(onionProxy, proxyRandomize);
15921602
if (!addrOnion.IsValid())
1593-
return InitError(strprintf(_("Invalid -onion address: '%s'"), onionArg));
1603+
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
15941604
SetProxy(NET_TOR, addrOnion);
15951605
SetLimited(NET_TOR, false);
15961606
}
@@ -1599,7 +1609,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
15991609
// see Step 2: parameter interactions for more information about these
16001610
fListen = GetBoolArg("-listen", DEFAULT_LISTEN);
16011611
fDiscover = GetBoolArg("-discover", true);
1602-
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
16031612
fRelayTxes = !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
16041613

16051614
if (fListen) {

0 commit comments

Comments
 (0)