fix: prevent invalid unitName cause AM crashed.

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe 2023-11-16 10:34:18 +08:00 committed by Comix
parent 3d8b834e3c
commit 5f08edbc74

View File

@ -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);