From 13c063a1500c34b33b25a8008394af2cb65534ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Tue, 4 Jul 2017 21:07:54 +0100 Subject: [PATCH] Fix a possible null pointer dereference. On some systems getlogin() function might fail to obtain user name. For now just check whether pointer is nullptr. In that case suspending plasma device automounter would not work but at least we will not crash. In future it might make sense to try to use other methods of obtaining login name, such as running "who am i". BUG: 381987 --- src/core/operationrunner.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/operationrunner.cpp b/src/core/operationrunner.cpp index 7253119..01771c7 100644 --- a/src/core/operationrunner.cpp +++ b/src/core/operationrunner.cpp @@ -51,8 +51,14 @@ void OperationRunner::run() // Disable Plasma removable device automounting unsigned int currentUid = getuid(); // 0 if running as root - unsigned int userId = getpwnam(getlogin())->pw_uid; // uid of original user before sudo - seteuid(userId); + char *login = getlogin(); + if (login != nullptr){ + passwd* pwnam = getpwnam(login); + if (pwnam != nullptr) { + unsigned int userId = pwnam->pw_uid; // uid of original user before sudo + seteuid(userId); + } + } QStringList modules; QDBusConnection bus = QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("sessionBus")); QDBusInterface kdedInterface( QStringLiteral("org.kde.kded5"), QStringLiteral("/kded"), QStringLiteral("org.kde.kded5"), bus );