QNetworkReply: fix potential nullptr access in loadFromCacheIfAllowed()

Fix a potential nullptr access in
QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed() on accessing to
QAbstractNetworkCache::data(). It is not yet clear in what cases
cached data can be null, especially if metaData is present,
but we have user reports of such crashes.

Amends a6776de0c7

Fixes: QTBUG-116788
Pick-to: 6.2 6.5 6.6
Change-Id: I548065c6f809d9d45db6dd785c28acbdc77621e2
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Vladimir Belyavsky 2023-09-06 12:49:45 +03:00
parent ac9e968755
commit 74fb2519e3

View File

@ -509,7 +509,8 @@ bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &h
it = cacheHeaders.findRawHeader("content-length");
if (it != cacheHeaders.rawHeaders.constEnd()) {
if (nc->data(httpRequest.url())->size() < it->second.toLongLong())
QIODevice *data = nc->data(httpRequest.url());
if (!data || data->size() < it->second.toLongLong())
return false; // The data is smaller than the content-length specified
}