From daa03c8e12666e7ec47da7ef38770642282b3c75 Mon Sep 17 00:00:00 2001 From: 0xd34df00d <0xd34df00d@gmail.com> Date: Sat, 12 Oct 2019 18:42:32 -0400 Subject: Fix potential SEGFAULT on connection error `socketError()` calls `connectToNextDNSHost()` which might cause `socketError()` synchronously (and recursively), thus not giving a change for updating `nextSrvRecordIdx`. Overall, this results in attempting to connect to the same DNS record recursively, until the stack is exhausted, resulting in SEGFAULT. One of the solutions (done in this commit) is to increment the record index _before_ attempting to connect. --- src/client/QXmppOutgoingClient.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/client') diff --git a/src/client/QXmppOutgoingClient.cpp b/src/client/QXmppOutgoingClient.cpp index 1fcb7c28..b9f01188 100644 --- a/src/client/QXmppOutgoingClient.cpp +++ b/src/client/QXmppOutgoingClient.cpp @@ -165,11 +165,10 @@ void QXmppOutgoingClientPrivate::connectToHost(const QString &host, quint16 port void QXmppOutgoingClientPrivate::connectToNextDNSHost() { + auto curIdx = nextSrvRecordIdx++; connectToHost( - dns.serviceRecords().at(nextSrvRecordIdx).target(), - dns.serviceRecords().at(nextSrvRecordIdx).port()); - - nextSrvRecordIdx++; + dns.serviceRecords().at(curIdx).target(), + dns.serviceRecords().at(curIdx).port()); } /// Constructs an outgoing client stream. -- cgit v1.2.3