Skip to content

fix: guard missing autostart desktop entry#369

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix/autostart-null-entry-crash
Jun 17, 2026
Merged

fix: guard missing autostart desktop entry#369
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix/autostart-null-entry-crash

Conversation

@yixinshark

Copy link
Copy Markdown
Contributor

Summary

  • Avoid dereferencing a null DesktopEntry when handling invalid autostart launch requests.
  • Log the affected app id and desktop/autostart source before returning the existing D-Bus error.

Test plan

  • cmake --build build --target dde-application-manager

Pms: BUG-366575

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @yixinshark, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Prevent ApplicationService::Launch from dereferencing a null DesktopEntry when an autostart launch is requested for an application without an autostart source. The method now logs the affected application context, sends the existing D-Bus error, and returns immediately.

防止 ApplicationService::Launch 在自启动请求缺少 autostart source 时解引用空的 DesktopEntry。现在会记录受影响应用的上下文,发送原有 D-Bus 错误,并立即返回。

Log: guard missing autostart desktop entry
Pms: BUG-366575
Change-Id: I6358d814ed3d620d9d7debf83ee67a80a24fec2f
@yixinshark
yixinshark force-pushed the fix/autostart-null-entry-crash branch from 4e55e06 to 7e3eaaa Compare June 17, 2026 01:38
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码精准修复了空指针解引用导致的段错误崩溃,并补充了完善的调试日志
逻辑严密、日志详实且无任何副作用,属于高质量的缺陷修复

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

修复了原代码在 ApplicationService::Launch 函数中 desktopEntry == nullptr 分支内缺少 return {} 导致的致命逻辑错误。原代码仅发送了 DBus 错误回复但未中断函数执行,导致后续代码继续使用空指针引发崩溃。新增的 return {}; 正确终止了函数流程。
建议:保持现有的防御性编程习惯,对所有异常前置判断均添加提前退出机制。

  • 2.代码质量(良好)✓

将硬编码的错误字符串提取为 const QString msg 变量,避免了字符串字面量的重复书写,提高了可维护性。同时新增的 qWarning 日志输出了 id()isAutostartLaunchdesktopSourceautostartSource 四个关键上下文变量,极大地提升了线上问题的排查效率。
建议:无

  • 3.代码性能(无性能问题)✓

新增的字符串对象构造与日志输出均位于异常处理的早期返回分支内,仅在应用未设置自启动的特定错误场景下触发,对正常启动流程的性能开销为零。
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码通过修复空指针解引用消除了潜在的拒绝服务攻击面(恶意或异常调用可导致 DBus 服务进程崩溃)。日志中打印的文件路径与应用 ID 属于 DBus 本地 IPC 环境下的常规排错信息,不构成敏感信息泄露风险。
建议:无

■ 【改进建议代码示例】

diff --git a/src/dbus/applicationservice.cpp b/src/dbus/applicationservice.cpp
index 4a0a4bb2..4626f45e 100644
--- a/src/dbus/applicationservice.cpp
+++ b/src/dbus/applicationservice.cpp
@@ -406,7 +406,13 @@ QDBusObjectPath ApplicationService::Launch(const QString &action, const QStringL
     }();
 
     if (desktopEntry == nullptr) {
-        safe_sendErrorReply(QDBusError::Failed, "This application is not set to autostart.");
+        const QString msg = "This application is not set to autostart.";
+        qWarning() << msg << "app:" << id()
+                   << "isAutostartLaunch:" << isAutostartLaunch
+                   << "desktopSource:" << m_desktopSource.sourcePath()
+                   << "autostartSource:" << m_autostartSource.m_filePath;
+        safe_sendErrorReply(QDBusError::Failed, msg);
+        return {};
     }
 
     // ignore action if it's not supported or autostart launch

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: robertkill, yixinshark

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@yixinshark

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 22d152c into linuxdeepin:master Jun 17, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants