From 60908d4b9b004e9b6c6f74425f5b6225aee7c728 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Mon, 4 Mar 2024 23:03:00 -0500 Subject: [PATCH] Fix parsing stat file for polkit --- src/gui/osutils/nixutils/NixUtils.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gui/osutils/nixutils/NixUtils.cpp b/src/gui/osutils/nixutils/NixUtils.cpp index 194b62058e..a2a0342058 100644 --- a/src/gui/osutils/nixutils/NixUtils.cpp +++ b/src/gui/osutils/nixutils/NixUtils.cpp @@ -339,14 +339,22 @@ quint64 NixUtils::getProcessStartTime() const QString processStatInfo = processStatStream.readLine(); processStatFile.close(); - auto startIndex = processStatInfo.indexOf(')', -1); + auto startIndex = processStatInfo.lastIndexOf(')'); if (startIndex != -1) { auto tokens = processStatInfo.midRef(startIndex + 2).split(' '); if (tokens.size() >= 20) { - return tokens[19].toULongLong(); + bool ok; + auto time = tokens[19].toULongLong(&ok); + if (!ok) { + qDebug() << "nixutils: failed to convert " << tokens[19] << " to an integer in " << processStatPath; + return 0; + } + return time; } + qDebug() << "nixutils: failed to find at least 20 values in " << processStatPath; + return 0; } - qDebug() << "nixutils: failed to parse " << processStatPath; + qDebug() << "nixutils: failed to find ')' in " << processStatPath; return 0; }