Bug 995417 - part 1 - netwerk/ changes for crashing on non-local connections; r=mcmanus

This commit is contained in:
Nathan Froyd 2014-04-15 15:38:55 -04:00
Родитель 611acd94a1
Коммит 70bac57591
1 изменённых файлов: 21 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set ts=4 sw=4 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@ -1171,14 +1172,31 @@ nsSocketTransport::InitiateSocket()
{
SOCKET_LOG(("nsSocketTransport::InitiateSocket [this=%p]\n", this));
static bool crashOnNonLocalConnections = !!getenv("MOZ_DISABLE_NONLOCAL_CONNECTIONS");
nsresult rv;
bool isLocal;
IsLocal(&isLocal);
if (gIOService->IsOffline()) {
bool isLocal;
IsLocal(&isLocal);
if (!isLocal)
return NS_ERROR_OFFLINE;
} else if (!isLocal) {
if (NS_SUCCEEDED(mCondition) &&
crashOnNonLocalConnections &&
!(IsIPAddrAny(&mNetAddr) || IsIPAddrLocal(&mNetAddr))) {
nsAutoCString ipaddr;
nsRefPtr<nsNetAddr> netaddr = new nsNetAddr(&mNetAddr);
netaddr->GetAddress(ipaddr);
fprintf_stderr(stderr,
"Non-local network connections are disabled and a connection "
"attempt to %s (%s) was made. You should only access hostnames "
"available via the test networking proxy (if running mochitests) "
"or from a test-specific httpd.js server (if running xpcshell tests)."
" Browser services should be disabled or redirected to a local server.",
mHost.get(), ipaddr.get());
MOZ_CRASH("Attempting to connect to non-local address!");
}
}
// Hosts/Proxy Hosts that are Local IP Literals should not be speculatively