Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[connectionagent] Add null check for all remote interface access. Fix…
…es JB#25393

Haven't seen crashes myself, but better be robust on these.
  • Loading branch information
pvuorela committed Dec 21, 2017
1 parent 022527f commit fe38dde
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
33 changes: 25 additions & 8 deletions connectionagentplugin/declarativeconnectionagent.cpp
Expand Up @@ -26,8 +26,8 @@
#define CONND_SERVICE "com.jolla.Connectiond"
#define CONND_PATH "/Connectiond"

DeclarativeConnectionAgent::DeclarativeConnectionAgent(QObject *parent):
QObject(parent),
DeclarativeConnectionAgent::DeclarativeConnectionAgent(QObject *parent)
: QObject(parent),
connManagerInterface(nullptr)
{
connectiondWatcher = new QDBusServiceWatcher(CONND_SERVICE,QDBusConnection::sessionBus(),
Expand Down Expand Up @@ -86,10 +86,10 @@ 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()) {
Expand All @@ -100,17 +100,16 @@ void DeclarativeConnectionAgent::sendUserReply(const QVariantMap &input)

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;
}

Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions connectionagentplugin/declarativeconnectionagent.h
Expand Up @@ -83,6 +83,7 @@ public slots:
void tetheringFinished(bool);

private:
bool checkValidness();
com::jolla::Connectiond *connManagerInterface;
QDBusServiceWatcher *connectiondWatcher;

Expand Down

0 comments on commit fe38dde

Please sign in to comment.