From fe38dde7c17eccb827693befc474465043d6c994 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Thu, 21 Dec 2017 14:06:12 +0200 Subject: [PATCH] =?UTF-8?q?[connectionagent]=C2=A0Add=20null=20check=20for?= =?UTF-8?q?=20all=20remote=20interface=20access.=20Fixes=20JB#25393?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Haven't seen crashes myself, but better be robust on these. --- .../declarativeconnectionagent.cpp | 37 ++++++++++++++----- .../declarativeconnectionagent.h | 1 + 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/connectionagentplugin/declarativeconnectionagent.cpp b/connectionagentplugin/declarativeconnectionagent.cpp index 0b3d05a..28b6233 100644 --- a/connectionagentplugin/declarativeconnectionagent.cpp +++ b/connectionagentplugin/declarativeconnectionagent.cpp @@ -26,9 +26,9 @@ #define CONND_SERVICE "com.jolla.Connectiond" #define CONND_PATH "/Connectiond" -DeclarativeConnectionAgent::DeclarativeConnectionAgent(QObject *parent): - QObject(parent), - connManagerInterface(nullptr) +DeclarativeConnectionAgent::DeclarativeConnectionAgent(QObject *parent) + : QObject(parent), + connManagerInterface(nullptr) { connectiondWatcher = new QDBusServiceWatcher(CONND_SERVICE,QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration | @@ -86,31 +86,30 @@ void DeclarativeConnectionAgent::connectToConnectiond() void DeclarativeConnectionAgent::sendUserReply(const QVariantMap &input) { - if (!connManagerInterface || !connManagerInterface->isValid()) { - Q_EMIT errorReported("","ConnectionAgent not available"); + if (!checkValidness()) { return; } + QDBusPendingReply<> reply = connManagerInterface->sendUserReply(input); reply.waitForFinished(); if (reply.isError()) { qDebug() << Q_FUNC_INFO << reply.error().message(); - Q_EMIT errorReported("",reply.error().message()); + Q_EMIT errorReported("", reply.error().message()); } } void DeclarativeConnectionAgent::sendConnectReply(const QString &replyMessage, int timeout) { - if (!connManagerInterface || !connManagerInterface->isValid()) { - Q_EMIT errorReported("","ConnectionAgent not available"); + if (!checkValidness()) { return; } + connManagerInterface->sendConnectReply(replyMessage,timeout); } void DeclarativeConnectionAgent::connectToType(const QString &type) { - if (!connManagerInterface || !connManagerInterface->isValid()) { - Q_EMIT errorReported("","ConnectionAgent not available"); + if (!checkValidness()) { return; } @@ -141,10 +140,28 @@ void DeclarativeConnectionAgent::connectiondUnregistered() void DeclarativeConnectionAgent::startTethering(const QString &type) { + if (!checkValidness()) { + return; + } + connManagerInterface->startTethering(type); } void DeclarativeConnectionAgent::stopTethering(bool keepPowered) { + if (!checkValidness()) { + return; + } + connManagerInterface->stopTethering(keepPowered); } + +bool DeclarativeConnectionAgent::checkValidness() +{ + if (!connManagerInterface || !connManagerInterface->isValid()) { + Q_EMIT errorReported("", "ConnectionAgent not available"); + return false; + } + + return true; +} diff --git a/connectionagentplugin/declarativeconnectionagent.h b/connectionagentplugin/declarativeconnectionagent.h index 1300c01..4478589 100644 --- a/connectionagentplugin/declarativeconnectionagent.h +++ b/connectionagentplugin/declarativeconnectionagent.h @@ -83,6 +83,7 @@ public slots: void tetheringFinished(bool); private: + bool checkValidness(); com::jolla::Connectiond *connManagerInterface; QDBusServiceWatcher *connectiondWatcher;