From: Olivier Goffart Date: Mon, 25 Sep 2017 14:44:33 +0000 (+0200) Subject: OAuth: Fix crash when closing the browser while identifying X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~701^2~37 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=79c775bcd819eb84e08bfd3260b8bcc2b2c50878;p=nextcloud-desktop.git 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. --- 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