Fix crash with KDE network detection
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 5 May 2014 18:37:36 +0000 (20:37 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 5 May 2014 18:39:36 +0000 (20:39 +0200)
If the network connection status changed during authentication phase,
Quassel would crash. This is caused by some old bits of code that still
assume that there's always a Peer around, which is no longer the case
after splitting off the AuthHandler.

This commit fixes that issue. Thanks to shadeslayer for the report and
really useful backtrace.

src/client/coreconnection.cpp
src/common/authhandler.cpp
src/common/authhandler.h

index 3650385..4928a8b 100644 (file)
@@ -211,8 +211,10 @@ bool CoreConnection::isLocalConnection() const
         return false;
     if (currentAccount().isInternal())
         return true;
-    if (_peer->isLocal())
-        return true;
+    if (_authHandler)
+        return _authHandler->isLocal();
+    if (_peer)
+        return _peer->isLocal();
 
     return false;
 }
index 9148e21..7c2905d 100644 (file)
@@ -18,6 +18,8 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
+#include <QHostAddress>
+
 #include "authhandler.h"
 
 AuthHandler::AuthHandler(QObject *parent)
@@ -43,6 +45,16 @@ void AuthHandler::setSocket(QTcpSocket *socket)
 }
 
 
+bool AuthHandler::isLocal() const
+{
+    if (socket()) {
+        if (socket()->peerAddress() == QHostAddress::LocalHost || socket()->peerAddress() == QHostAddress::LocalHostIPv6)
+            return true;
+    }
+    return false;
+}
+
+
 // Some errors (e.g. connection refused) don't trigger a disconnected() from the socket, so send this explicitly
 // (but make sure it's only sent once!)
 void AuthHandler::onSocketError(QAbstractSocket::SocketError error)
index cfed51e..cc03588 100644 (file)
@@ -36,6 +36,8 @@ public:
 
     QTcpSocket *socket() const;
 
+    bool isLocal() const;
+
     virtual void handle(const Protocol::RegisterClient &) { invalidMessage(); }
     virtual void handle(const Protocol::ClientDenied &) { invalidMessage(); }
     virtual void handle(const Protocol::ClientRegistered &) { invalidMessage(); }