From 79c775bcd819eb84e08bfd3260b8bcc2b2c50878 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 25 Sep 2017 16:44:33 +0200 Subject: [PATCH] OAuth: Fix crash when closing the browser while identifying To reproduce, log in and click "authorize" on the browser, then close the browser before the client has replied, (but after redirected to localhost, i.e. when the client is asking the server for the token) The problem is that socket can be destroyed so we don't need to answer on a destroyed socket. --- src/gui/creds/oauth.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/creds/oauth.cpp b/src/gui/creds/oauth.cpp index 05ef093b3..f06fe3a3c 100644 --- a/src/gui/creds/oauth.cpp +++ b/src/gui/creds/oauth.cpp @@ -34,6 +34,8 @@ OAuth::~OAuth() static void httpReplyAndClose(QTcpSocket *socket, const char *code, const char *html, const char *moreHeaders = nullptr) { + if (!socket) + return; // socket can have been deleted if the browser was closed socket->write("HTTP/1.1 "); socket->write(code); socket->write("\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: "); @@ -62,7 +64,7 @@ void OAuth::start() return; QObject::connect(&_server, &QTcpServer::newConnection, this, [this] { - while (QTcpSocket *socket = _server.nextPendingConnection()) { + while (QPointer socket = _server.nextPendingConnection()) { QObject::connect(socket, &QTcpSocket::disconnected, socket, &QTcpSocket::deleteLater); QObject::connect(socket, &QIODevice::readyRead, this, [this, socket] { QByteArray peek = socket->peek(qMin(socket->bytesAvailable(), 4000LL)); //The code should always be within the first 4K -- 2.30.2