Skip to content

Commit f36bdf0

Browse files
committed
Enable host lookups for -proxy and -onion parameters
* Extends -dns parameter (via fNameLookup) to control these two new parameters in addition to -addnode, -connect, and -seednode * Moves fNameLookup assignment earlier as needed * Changes -proxy and -onion to use Lookup() instead of LookupNumeric()
1 parent 390a39b commit f36bdf0

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/init.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,16 +1248,23 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12481248
}
12491249
}
12501250

1251+
// Check for host lookup allowed before parsing any network related parameters
1252+
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
1253+
12511254
bool proxyRandomize = GetBoolArg("-proxyrandomize", DEFAULT_PROXYRANDOMIZE);
12521255
// -proxy sets a proxy for all outgoing network traffic
12531256
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
12541257
std::string proxyArg = GetArg("-proxy", "");
12551258
SetLimited(NET_TOR);
12561259
if (proxyArg != "" && proxyArg != "0") {
1257-
CService resolved(LookupNumeric(proxyArg.c_str(), 9050));
1258-
proxyType addrProxy = proxyType(resolved, proxyRandomize);
1260+
CService proxyAddr;
1261+
if (!Lookup(proxyArg.c_str(), proxyAddr, 9050, fNameLookup)) {
1262+
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
1263+
}
1264+
1265+
proxyType addrProxy = proxyType(proxyAddr, proxyRandomize);
12591266
if (!addrProxy.IsValid())
1260-
return InitError(strprintf(_("Invalid -proxy address: '%s'"), proxyArg));
1267+
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
12611268

12621269
SetProxy(NET_IPV4, addrProxy);
12631270
SetProxy(NET_IPV6, addrProxy);
@@ -1274,10 +1281,13 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12741281
if (onionArg == "0") { // Handle -noonion/-onion=0
12751282
SetLimited(NET_TOR); // set onions as unreachable
12761283
} else {
1277-
CService resolved(LookupNumeric(onionArg.c_str(), 9050));
1278-
proxyType addrOnion = proxyType(resolved, proxyRandomize);
1284+
CService onionProxy;
1285+
if (!Lookup(onionArg.c_str(), onionProxy, 9050, fNameLookup)) {
1286+
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
1287+
}
1288+
proxyType addrOnion = proxyType(onionProxy, proxyRandomize);
12791289
if (!addrOnion.IsValid())
1280-
return InitError(strprintf(_("Invalid -onion address: '%s'"), onionArg));
1290+
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
12811291
SetProxy(NET_TOR, addrOnion);
12821292
SetLimited(NET_TOR, false);
12831293
}
@@ -1286,7 +1296,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12861296
// see Step 2: parameter interactions for more information about these
12871297
fListen = GetBoolArg("-listen", DEFAULT_LISTEN);
12881298
fDiscover = GetBoolArg("-discover", true);
1289-
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
12901299
fRelayTxes = !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
12911300

12921301
if (fListen) {

0 commit comments

Comments
 (0)