Skip to content

Commit 90cb2a2

Browse files
committed
Merge #9774: Enable host lookups for -proxy and -onion parameters
f36bdf0 Enable host lookups for -proxy and -onion parameters (Johnathan Corgan) Tree-SHA512: 40f5ef3954721333e58d34653874d9f6ac5426c817762d132838f3b6f968ca5ca05aa56d02fd742cb5a8dc040f1a28dad6d54f667342eceba62fb2af18b58fc0
2 parents 67c5cc1 + f36bdf0 commit 90cb2a2

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
@@ -1266,16 +1266,23 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12661266
}
12671267
}
12681268

1269+
// Check for host lookup allowed before parsing any network related parameters
1270+
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
1271+
12691272
bool proxyRandomize = GetBoolArg("-proxyrandomize", DEFAULT_PROXYRANDOMIZE);
12701273
// -proxy sets a proxy for all outgoing network traffic
12711274
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
12721275
std::string proxyArg = GetArg("-proxy", "");
12731276
SetLimited(NET_TOR);
12741277
if (proxyArg != "" && proxyArg != "0") {
1275-
CService resolved(LookupNumeric(proxyArg.c_str(), 9050));
1276-
proxyType addrProxy = proxyType(resolved, proxyRandomize);
1278+
CService proxyAddr;
1279+
if (!Lookup(proxyArg.c_str(), proxyAddr, 9050, fNameLookup)) {
1280+
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
1281+
}
1282+
1283+
proxyType addrProxy = proxyType(proxyAddr, proxyRandomize);
12771284
if (!addrProxy.IsValid())
1278-
return InitError(strprintf(_("Invalid -proxy address: '%s'"), proxyArg));
1285+
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
12791286

12801287
SetProxy(NET_IPV4, addrProxy);
12811288
SetProxy(NET_IPV6, addrProxy);
@@ -1292,10 +1299,13 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12921299
if (onionArg == "0") { // Handle -noonion/-onion=0
12931300
SetLimited(NET_TOR); // set onions as unreachable
12941301
} else {
1295-
CService resolved(LookupNumeric(onionArg.c_str(), 9050));
1296-
proxyType addrOnion = proxyType(resolved, proxyRandomize);
1302+
CService onionProxy;
1303+
if (!Lookup(onionArg.c_str(), onionProxy, 9050, fNameLookup)) {
1304+
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
1305+
}
1306+
proxyType addrOnion = proxyType(onionProxy, proxyRandomize);
12971307
if (!addrOnion.IsValid())
1298-
return InitError(strprintf(_("Invalid -onion address: '%s'"), onionArg));
1308+
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
12991309
SetProxy(NET_TOR, addrOnion);
13001310
SetLimited(NET_TOR, false);
13011311
}
@@ -1304,7 +1314,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
13041314
// see Step 2: parameter interactions for more information about these
13051315
fListen = GetBoolArg("-listen", DEFAULT_LISTEN);
13061316
fDiscover = GetBoolArg("-discover", true);
1307-
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
13081317
fRelayTxes = !GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
13091318

13101319
if (fListen) {

0 commit comments

Comments
 (0)