summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2024-02-07 18:56:22 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2024-03-12 14:23:54 +0100
commit22c99cf498103c86baa5a415ca34630396e5b6aa (patch)
tree65e86687aee75c0431cf1752cce8de82cc59663f /src/network
parentc468dfedd6413994a72c41a53eadd1944eb52e6d (diff)
QHttp2ProtocolHandler: prevent truncation in arithmetic operations
On 64-bit systems, both the requests.size() and the activeStreams.size() were truncated to uint32_t values from int64_t ones. While extremely unlikely that either will contain more than 4Gi elements, avoid the truncation by verifying that the `max` amount of streams is larger than the activeStreams, and then using size_t for the range. Pick-to: 6.7 Change-Id: I50644cb634bab0f020acf9aea1d03744b11dbe51 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qhttp2protocolhandler.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp
index d25be851bf..6388044094 100644
--- a/src/network/access/qhttp2protocolhandler.cpp
+++ b/src/network/access/qhttp2protocolhandler.cpp
@@ -326,11 +326,11 @@ bool QHttp2ProtocolHandler::sendRequest()
initReplyFromPushPromise(message, key);
}
- const auto streamsToUse = std::min<quint32>(maxConcurrentStreams > quint32(activeStreams.size())
- ? maxConcurrentStreams - quint32(activeStreams.size()) : 0,
- requests.size());
+ Q_ASSERT(qint64(maxConcurrentStreams) >= activeStreams.size());
+ const size_t streamsToUse = std::min(maxConcurrentStreams - size_t(activeStreams.size()),
+ size_t(requests.size()));
auto it = requests.begin();
- for (quint32 i = 0; i < streamsToUse; ++i) {
+ for (size_t i = 0; i < streamsToUse; ++i) {
const qint32 newStreamID = createNewStream(*it);
if (!newStreamID) {
// TODO: actually we have to open a new connection.