From 0fa7fca31e668df6a0971e4f9d1a25bfa5f111f5 Mon Sep 17 00:00:00 2001 From: FranciscoPombal Date: Fri, 19 Jun 2020 16:28:47 +0100 Subject: [PATCH 1/2] Fix truncation when parsing HTTP request query Closes #13029. Fixes an issue with truncation of a QByteArray at the first '\0' byte when parsing HTTP request query strings. Previously, the operands of the ternary expression were of different types. Most likely this was leading to a conversion of the result to some kind of '\0'-terminated string type somewhere along the way, in turn causing its truncation at the first '\0' byte once converted back to QByteArray. For some reason this bug was only present on Windows (MSVC). --- src/base/http/requestparser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/http/requestparser.cpp b/src/base/http/requestparser.cpp index e6e1853f6..3f74b7a76 100644 --- a/src/base/http/requestparser.cpp +++ b/src/base/http/requestparser.cpp @@ -202,7 +202,7 @@ bool RequestParser::parseRequestLine(const QString &line) const QByteArray valueComponent = midView(param, (eqCharPos + 1)); const QString paramName = QString::fromUtf8(QByteArray::fromPercentEncoding(nameComponent).replace('+', ' ')); const QByteArray paramValue = valueComponent.isNull() - ? "" + ? QByteArray("") : QByteArray::fromPercentEncoding(valueComponent).replace('+', ' '); m_request.query[paramName] = paramValue; From a1809a43f8a17dec8119c5de5ee2fe700457b4d8 Mon Sep 17 00:00:00 2001 From: FranciscoPombal Date: Tue, 23 Jun 2020 11:40:10 +0100 Subject: [PATCH 2/2] Add QT_NO_CAST_FROM_BYTEARRAY to compile definitions Prevents bugs like #13029, even if the ternary expression operands have different types. --- src/CMakeLists.txt | 1 + src/src.pro | 1 + 2 files changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c45bb701..a73d89e81 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) # defines add_definitions(-DQT_DEPRECATED_WARNINGS) add_definitions(-DQT_NO_CAST_TO_ASCII) +add_definitions(-DQT_NO_CAST_FROM_BYTEARRAY) add_definitions(-DQT_USE_QSTRINGBUILDER) add_definitions(-DQT_STRICT_ITERATORS) diff --git a/src/src.pro b/src/src.pro index b8e970e57..52b325491 100644 --- a/src/src.pro +++ b/src/src.pro @@ -57,6 +57,7 @@ include(../version.pri) # Qt defines DEFINES += QT_DEPRECATED_WARNINGS DEFINES += QT_NO_CAST_TO_ASCII +DEFINES += QT_NO_CAST_FROM_BYTEARRAY DEFINES += QT_USE_QSTRINGBUILDER DEFINES += QT_STRICT_ITERATORS