From 71d5c8373dc76fb1b994a1185ecae3ae8d42b689 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 8 Oct 2020 16:09:53 +0200 Subject: Add sanity checks to RPC parse, so we don't reset everything If we get a malformed empty reply, we would previously reset all the variables, so the display text would reset to a generic string. --- src/saverwidget.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/saverwidget.cpp b/src/saverwidget.cpp index 359c2bd..1a4a14c 100644 --- a/src/saverwidget.cpp +++ b/src/saverwidget.cpp @@ -113,12 +113,17 @@ void SaverWidget::reloadValues() connect(_unixSocket, &QLocalSocket::connected, [=]() { qDebug() << "Connected to daewmweon"; _unixSocket->write((QLatin1String("get ") + _display).toLocal8Bit()); - QTimer::singleShot(1000, [this]() { + QTimer::singleShot(2000, [this]() { _unixSocket->disconnectFromServer(); + this->parseDaemonData(); }); }); connect(_unixSocket, QOverload::of(&QLocalSocket::error), [=](QLocalSocket::LocalSocketError err) { - qDebug() << "Local socket error:" << err; + if (err != QLocalSocket::PeerClosedError) { + qDebug() << "Local socket error:" << err; + } else { + this->parseDaemonData(); + } }); connect(_unixSocket, &QLocalSocket::disconnected, this, &SaverWidget::parseDaemonData); _unixSocket->connectToServer("/run/idle-daemon"); @@ -131,8 +136,9 @@ void SaverWidget::parseDaemonData() #define SEC_NONE 0 #define SEC_GENERAL 1 #define SEC_ME 2 -#define STORE(x) else if (key == QLatin1String( #x )) x = value.toString() +#define STORE(x) else if (key == QLatin1String( #x )) ok++, x = value.toString() int sec = SEC_NONE; + int ok = 0; QString nextAction, nextActionTime, logoutTime, locked; while (!ts.atEnd()) { line = ts.readLine(); @@ -142,8 +148,10 @@ void SaverWidget::parseDaemonData() // Section if (line == QLatin1String("[General]")) { sec = SEC_GENERAL; + ok++; } else if ( line == "[" + _display + "]") { sec = SEC_ME; + ok++; } else { sec = SEC_NONE; } @@ -165,6 +173,8 @@ void SaverWidget::parseDaemonData() } } } + if (ok < 3) + return; // Bad data received, ignore if (nextAction.isEmpty() || nextAction == QLatin1String("none") || nextActionTime.isEmpty()) { _shutdownDeadline = 0; } else { -- cgit v1.2.3-55-g7522