Check for loopback address if network access is unavailable

A loopback address warrants the same exception as local files.

Task-number: QTBUG-59219
Change-Id: Ie0a75faa558d6596455da38656c8749c994d0fd8
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Mårten Nordheim 2017-08-10 11:22:42 +02:00
parent 8bebded9ab
commit eb2b635154

View File

@ -71,6 +71,8 @@
#include "qthread.h" #include "qthread.h"
#include <QHostInfo>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QNetworkAccessFileBackendFactory, fileBackend) Q_GLOBAL_STATIC(QNetworkAccessFileBackendFactory, fileBackend)
@ -1324,11 +1326,17 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
} }
#ifndef QT_NO_BEARERMANAGEMENT #ifndef QT_NO_BEARERMANAGEMENT
// Return a disabled network reply if network access is disabled. // Return a disabled network reply if network access is disabled.
// Except if the scheme is empty or file://. // Except if the scheme is empty or file:// or if the host resolves to a loopback address.
if (d->networkAccessible == NotAccessible && !isLocalFile) { if (d->networkAccessible == NotAccessible && !isLocalFile) {
QHostAddress dest;
QString host = req.url().host().toLower();
if (!(dest.setAddress(host) && dest.isLoopback()) && host != QLatin1String("localhost")
&& host != QHostInfo::localHostName().toLower()) {
return new QDisabledNetworkReply(this, req, op); return new QDisabledNetworkReply(this, req, op);
} }
}
if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) { if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) {
QNetworkConfigurationManager manager; QNetworkConfigurationManager manager;