From 2eeee81b67ce4fc81793c51bafd2cc1b33076c05 Mon Sep 17 00:00:00 2001 From: Aleksey Lysenko Date: Tue, 3 Jan 2017 22:59:36 +0200 Subject: Fixed possible block clearing in QWebSocketDataProcessor::process method In QWebSocketDataProcessor::process() the signals text(binary)MessageReceived are emitted before clear() method. If signal handler blocks loop (for example, using QDialog::exec()), clear() will be called only after resuming loop. It may lead to the data corruption due to the fact that QWebSocketDataProcessor clearing won't be performed before the new data arrived. Task-number: QTBUG-55506 Change-Id: Ib7016a91d3987dec7c1af977b17f86a53568c413 Reviewed-by: Timur Pocheptsov --- src/websockets/qwebsocketdataprocessor.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/websockets/qwebsocketdataprocessor.cpp b/src/websockets/qwebsocketdataprocessor.cpp index 520ecdc..d9fc550 100644 --- a/src/websockets/qwebsocketdataprocessor.cpp +++ b/src/websockets/qwebsocketdataprocessor.cpp @@ -182,12 +182,16 @@ void QWebSocketDataProcessor::process(QIODevice *pIoDevice) } if (frame.isFinalFrame()) { - if (m_opCode == QWebSocketProtocol::OpCodeText) - Q_EMIT textMessageReceived(m_textMessage); - else - Q_EMIT binaryMessageReceived(m_binaryMessage); - clear(); isDone = true; + if (m_opCode == QWebSocketProtocol::OpCodeText) { + const QString textMessage(m_textMessage); + clear(); + Q_EMIT textMessageReceived(textMessage); + } else { + const QByteArray binaryMessage(m_binaryMessage); + clear(); + Q_EMIT binaryMessageReceived(binaryMessage); + } } } } else { -- cgit v1.2.1