Commit fe38dde7 authored by Pekka Vuorela's avatar Pekka Vuorela

[connectionagent] Add null check for all remote interface access. Fixes JB#25393

Haven't seen crashes myself, but better be robust on these.
parent 022527f8
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
#define CONND_SERVICE "com.jolla.Connectiond" #define CONND_SERVICE "com.jolla.Connectiond"
#define CONND_PATH "/Connectiond" #define CONND_PATH "/Connectiond"
DeclarativeConnectionAgent::DeclarativeConnectionAgent(QObject *parent): DeclarativeConnectionAgent::DeclarativeConnectionAgent(QObject *parent)
QObject(parent), : QObject(parent),
connManagerInterface(nullptr) connManagerInterface(nullptr)
{ {
connectiondWatcher = new QDBusServiceWatcher(CONND_SERVICE,QDBusConnection::sessionBus(), connectiondWatcher = new QDBusServiceWatcher(CONND_SERVICE,QDBusConnection::sessionBus(),
...@@ -86,31 +86,30 @@ void DeclarativeConnectionAgent::connectToConnectiond() ...@@ -86,31 +86,30 @@ void DeclarativeConnectionAgent::connectToConnectiond()
void DeclarativeConnectionAgent::sendUserReply(const QVariantMap &input) void DeclarativeConnectionAgent::sendUserReply(const QVariantMap &input)
{ {
if (!connManagerInterface || !connManagerInterface->isValid()) { if (!checkValidness()) {
Q_EMIT errorReported("","ConnectionAgent not available");
return; return;
} }
QDBusPendingReply<> reply = connManagerInterface->sendUserReply(input); QDBusPendingReply<> reply = connManagerInterface->sendUserReply(input);
reply.waitForFinished(); reply.waitForFinished();
if (reply.isError()) { if (reply.isError()) {
qDebug() << Q_FUNC_INFO << reply.error().message(); 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) void DeclarativeConnectionAgent::sendConnectReply(const QString &replyMessage, int timeout)
{ {
if (!connManagerInterface || !connManagerInterface->isValid()) { if (!checkValidness()) {
Q_EMIT errorReported("","ConnectionAgent not available");
return; return;
} }
connManagerInterface->sendConnectReply(replyMessage,timeout); connManagerInterface->sendConnectReply(replyMessage,timeout);
} }
void DeclarativeConnectionAgent::connectToType(const QString &type) void DeclarativeConnectionAgent::connectToType(const QString &type)
{ {
if (!connManagerInterface || !connManagerInterface->isValid()) { if (!checkValidness()) {
Q_EMIT errorReported("","ConnectionAgent not available");
return; return;
} }
...@@ -141,10 +140,28 @@ void DeclarativeConnectionAgent::connectiondUnregistered() ...@@ -141,10 +140,28 @@ void DeclarativeConnectionAgent::connectiondUnregistered()
void DeclarativeConnectionAgent::startTethering(const QString &type) void DeclarativeConnectionAgent::startTethering(const QString &type)
{ {
if (!checkValidness()) {
return;
}
connManagerInterface->startTethering(type); connManagerInterface->startTethering(type);
} }
void DeclarativeConnectionAgent::stopTethering(bool keepPowered) void DeclarativeConnectionAgent::stopTethering(bool keepPowered)
{ {
if (!checkValidness()) {
return;
}
connManagerInterface->stopTethering(keepPowered); connManagerInterface->stopTethering(keepPowered);
} }
bool DeclarativeConnectionAgent::checkValidness()
{
if (!connManagerInterface || !connManagerInterface->isValid()) {
Q_EMIT errorReported("", "ConnectionAgent not available");
return false;
}
return true;
}
...@@ -83,6 +83,7 @@ signals: ...@@ -83,6 +83,7 @@ signals:
void tetheringFinished(bool); void tetheringFinished(bool);
private: private:
bool checkValidness();
com::jolla::Connectiond *connManagerInterface; com::jolla::Connectiond *connManagerInterface;
QDBusServiceWatcher *connectiondWatcher; QDBusServiceWatcher *connectiondWatcher;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment