mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 06:55:59 +03:00
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.
This commit is contained in:
parent
278129b286
commit
7af81f7665
1 changed files with 3 additions and 1 deletions
|
@ -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<QTcpSocket> 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
|
||||
|
|
Loading…
Reference in a new issue