From 5f08edbc74d66b35cc7eb9e7e18530c2aa3b7f56 Mon Sep 17 00:00:00 2001 From: ComixHe Date: Thu, 16 Nov 2023 10:34:18 +0800 Subject: [PATCH] fix: prevent invalid unitName cause AM crashed. Signed-off-by: ComixHe --- src/global.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/global.h b/src/global.h index ba68baf..6f217e9 100644 --- a/src/global.h +++ b/src/global.h @@ -498,7 +498,14 @@ inline unitInfo processUnitName(const QString &unitName) QString launcher; QString applicationId; + qDebug() << "process unit:" << unitName; + decltype(auto) appPrefix = u8"app-"; + if (!unitName.startsWith(appPrefix)) { + qDebug() << "this unit " << unitName << "isn't an app unit."; + return {}; + } + auto unit = unitName.sliced(sizeof(appPrefix) - 1); if (unit.endsWith(".service")) { @@ -514,7 +521,9 @@ inline unitInfo processUnitName(const QString &unitName) if (rest.size() == 2) { launcher = rest.takeFirst(); } - applicationId = rest.takeFirst(); + if (rest.size() == 1) { + applicationId = rest.takeFirst(); + } } else if (unit.endsWith(".scope")) { auto lastDotIndex = unit.lastIndexOf('.'); auto app = unit.sliced(0, lastDotIndex);