From 536e17372803e7c9557e4a59ae8dad0405f11cd2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 6 Dec 2022 22:04:32 +0100 Subject: QNetworkRequest: Make header parsing locale-independent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing header parsing used C's tolower() function for case-insensitive switching over the first character of the header. However, that function's result depends on the current locale. Since the parser is supposed to match the likes of "If-Match" and "If-None-Match", matching may fail in locales, such as Turkish, where tolower(I) is ı (LATIN SMALL LETTER DOTLESS I) (or I, if the former isn't representable in the current charset), causing a False Negative. To fix, use the US-ASCII-only QtMiscUtils::toAsciiLower() function, which has the added advantage that it's inline. Replace at(0) with front() as a drive-by. The WASM copy of the function is hopelessly outdated (recognizes less headers than the QNetworkRequest original). [ChangeLog][QtNetwork] Fixed a bug where certain QNetworkRequest::KnownHeaders wouldn't be recognized as such in certain locales. Pick-to: 6.4 6.2 5.15 Task-number: QTBUG-109235 Change-Id: Ib147ab64803bb868647dd07ad657d785071242ea Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot Reviewed-by: Mårten Nordheim --- src/network/access/qnetworkreplywasmimpl.cpp | 3 ++- src/network/access/qnetworkrequest.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/network/access') diff --git a/src/network/access/qnetworkreplywasmimpl.cpp b/src/network/access/qnetworkreplywasmimpl.cpp index 70d2a6be44..b05fae73db 100644 --- a/src/network/access/qnetworkreplywasmimpl.cpp +++ b/src/network/access/qnetworkreplywasmimpl.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -346,7 +347,7 @@ static int parseHeaderName(const QByteArray &headerName) if (headerName.isEmpty()) return -1; - switch (tolower(headerName.at(0))) { + switch (QtMiscUtils::toAsciiLower(headerName.front())) { case 'c': if (qstricmp(headerName.constData(), "content-type") == 0) return QNetworkRequest::ContentTypeHeader; diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index af5113ce2f..7126b8ad86 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -13,6 +13,7 @@ #include "QtCore/qshareddata.h" #include "QtCore/qlocale.h" #include "QtCore/qdatetime.h" +#include "QtCore/private/qtools_p.h" #include #if QT_CONFIG(datestring) @@ -1101,7 +1102,7 @@ static int parseHeaderName(const QByteArray &headerName) if (headerName.isEmpty()) return -1; - switch (tolower(headerName.at(0))) { + switch (QtMiscUtils::toAsciiLower(headerName.front())) { case 'c': if (headerName.compare("content-type", Qt::CaseInsensitive) == 0) return QNetworkRequest::ContentTypeHeader; -- cgit v1.2.3