From 5e2f22f8a12cf3548beca2245c7ce7bf0a464d53 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 4 Sep 2023 20:11:17 +0200 Subject: [PATCH] QHostInfo::lookupHost: do not violate lookupHostImpl preconditions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lookupHostImpl requires either `receiver` or `slotObj` to be non-null. Since this code path deals with the string-based slots, `slotObj` is going to be null, therefore check that `receiver` is non-null. For completeness: also check that `member` is non-null. Emit a warning (à la QObject::connect) in case the user did something wrong. Change-Id: Ic6dcd51d7ddd977b121484369b1aef48844364c5 Reviewed-by: Thiago Macieira --- src/network/kernel/qhostinfo.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index 9be6abced0..9e4a3fae83 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -225,6 +225,10 @@ static int nextId() */ int QHostInfo::lookupHost(const QString &name, QT7_ONLY(const) QObject *receiver, const char *member) { + if (!receiver || !member) { + qWarning("QHostInfo::lookupHost: both the receiver and the member to invoke must be non-null"); + return -1; + } return QHostInfo::lookupHostImpl(name, receiver, nullptr, member); }