Fix assertion when encountering invalid header line.
authorMilian Wolff <mail@milianw.de>
Thu, 6 Feb 2014 16:40:24 +0000 (17:40 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 6 Feb 2014 19:17:17 +0000 (20:17 +0100)
The server test sets an empty identifier which results in a
headerLine containing "Server: ". The split then yields a list
with a single entry ("Server"). Calling [1] on it asserts then.

QFATAL : tst_QWebSocketServer::tst_connectivity()
 ASSERT failure in QList<T>::operator[]: "index out of range", file
/ssd/milian/projects/compiled/qt5/include/QtCore/qlist.h, line 476

Change-Id: I3e5c4750b304b2a4a5669a39e2d65a6b3e4e99cf
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
src/websockets/qwebsocket_p.cpp

index 5d58fec..5f59b54 100644 (file)
@@ -872,7 +872,9 @@ void QWebSocketPrivate::processHandshake(QTcpSocket *pSocket)
         while (!headerLine.isEmpty()) {
             const QStringList headerField = headerLine.split(QStringLiteral(": "),
                                                              QString::SkipEmptyParts);
-            headers.insertMulti(headerField[0], headerField[1]);
+            if (headerField.size() == 2) {
+                headers.insertMulti(headerField[0], headerField[1]);
+            }
             headerLine = readLine(pSocket);
         }