diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2022-03-29 17:03:05 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2022-04-01 09:50:22 +0000 |
commit | 631fb7665fb53521df2cedb186a8e1e370b2aaa4 (patch) | |
tree | 5db842459de6c442391f18bfc08470b636822f3c /src | |
parent | a864f340543486e1962c72538b9e56e520f7cee4 (diff) | |
download | qtwebsockets-631fb7665fb53521df2cedb186a8e1e370b2aaa4.tar.gz |
Fix handshake looping infinitely making no progress
The processHandshake function may make no progress and return.
The loop calling processHandshake previously had no way of knowing this
and would happily loop forever despite the outcome being the same every
time.
This was particularly noticeable with any response that doesn't include
the \r\n\r\n sequence the first time we call processHandshake.
Since processHandshake either fails or succeeds, not performing any
partial-reads, we simply move it out of the loop and restructure some of
the code around it.
Pick-to: 6.3 6.3.0
Fixes: QTBUG-102111
Change-Id: I3955e4b90eb1be0a0ef5dfcf8a46921a086a8b49
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/websockets/qwebsocket_p.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp index 2cb5419..8385cb1 100644 --- a/src/websockets/qwebsocket_p.cpp +++ b/src/websockets/qwebsocket_p.cpp @@ -1191,13 +1191,16 @@ void QWebSocketPrivate::processData() { if (!m_pSocket) // disconnected with data still in-bound return; - while (m_pSocket->bytesAvailable()) { - if (state() == QAbstractSocket::ConnectingState) { - if (!m_pSocket->canReadLine()) - return; - processHandshake(m_pSocket); - } else if (!m_dataProcessor->process(m_pSocket)) { + if (state() == QAbstractSocket::ConnectingState) { + if (!m_pSocket->canReadLine()) return; + processHandshake(m_pSocket); + // That may have changed state(), recheck in the next 'if' below. + } + if (state() != QAbstractSocket::ConnectingState) { + while (m_pSocket->bytesAvailable()) { + if (!m_dataProcessor->process(m_pSocket)) + return; } } } |