Skip to content
This repository was archived by the owner on Aug 26, 2026. It is now read-only.

fix(accounts): guard userList against unavailable Accounts service - #23

Closed
zccrs wants to merge 1 commit into
linuxdeepin:masterfrom
zccrs:fix/accounts-userList-service-guard
Closed

fix(accounts): guard userList against unavailable Accounts service#23
zccrs wants to merge 1 commit into
linuxdeepin:masterfrom
zccrs:fix/accounts-userList-service-guard

Conversation

@zccrs

@zccrs zccrs commented Aug 25, 2026

Copy link
Copy Markdown
Member

Problem

DAccountsManager::userList()org.freedesktop.Accounts 不可用时直接解引用空 QArrayDataPointer<QDBusObjectPath>needsDetach(this=0x0)),导致 SIGSEGV(exit 139)。gdb 栈:

#0 QArrayDataPointer<QDBusObjectPath>::needsDetach(this=0x0)
#1 QMovableArrayOps<QDBusObjectPath>::emplace
#2 DAccountsManager::userList() at daccountsmanager.cpp:52
#3 UserModel::UserModel at treeland/src/greeter/usermodel.cpp:64
#4 Helper::init -> QQmlEngine::singletonInstance<UserModel>

treeland 启动时必现:Helper::init 无条件实例化 UserModel QML 单例,dde-system-daemonorg.deepin.dde.Accounts1)因 Go concurrent map 竞态崩溃后,org.freedesktop.Accounts 虽在但 QDBusPendingReply::value() 的解包路径在部分传输下返回 QDBusArgument 而非 QList<QDBusObjectPath>,原有 !isValid 检查不足,遍历空指针列表触发崩溃。treeland 侧虽已加 isServiceRegistered 防护(ca5936d),库侧仍需健壮。

Fix

  • 调用前 QDBusConnection::systemBus().interface()->isServiceRegistered("org.freedesktop.Accounts"),不可用时直接返回 DUnexpected{ServiceUnknown},避免发 DBus
  • waitForFinished 后同时检查 isError() || !isValid()
  • const auto value = reply.value() 拷贝后遍历,跳过空 path(),避免解包失败时的空 QList 解引用

已在 archlinux + accounts-daemon 788 + treeland build/src/treeland 验证:原库 ./build/src/treelandSIGSEGV,补丁库 LD_LIBRARY_PATH=/tmp/dtk_build/src 后正常启动至锁屏/多任务视图,无崩溃。

Test

  • ./tmp/test3 直接调用 DAccountsManager::userList() 返回 4 用户正常
  • treeland 原分支 + 补丁库:timeout 4 treelandEXIT:139 变为 EXIT:124wayland-0.lock 正常退出),无 SIGSEGV
  • cmake --build /tmp/dtk_build 通过

Log: fix accounts userList SIGSEGV when service unavailable

Summary by Sourcery

Harden account user listing against unavailable services and malformed D-Bus responses.

Bug Fixes:

  • Prevent crashes in DAccountsManager::userList() when the Accounts D-Bus service is unavailable or returns invalid user data.
  • Return a service-unavailable error instead of issuing D-Bus requests when org.freedesktop.Accounts is not registered.

Enhancements:

  • Improve validation of D-Bus replies and ignore empty user object paths during user list processing.

DAccountsManager::userList() dereferences a null QArrayDataPointer
(SIGSEGV) when org.freedesktop.Accounts is not available because
QDBusPendingReply::value() is accessed without checking service
registration or reply validity. The crash is triggered via
Treeland's Helper::init -> UserModel singleton during compositor
startup (QML UserModel at src/greeter/usermodel.cpp:64) when
dde-system-daemon fails to activate (Go concurrent map panic).

Add isServiceRegistered guard before DBus call, check isError/isValid,
and iterate over a copied value with empty-path guard to avoid
demarshall failures. Fixes SIGSEGV (exit 139) on treeland startup
when Accounts service is down.

Log: fix accounts userList SIGSEGV when service unavailable
PMS: TASK-393829
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zccrs

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

@sourcery-ai

sourcery-ai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Hardens DAccountsManager::userList() against an unavailable Accounts service and invalid D-Bus payloads, preventing the startup-time SIGSEGV while preserving normal user enumeration.

Sequence diagram for guarded Accounts user listing

sequenceDiagram
    participant UserModel
    participant DAccountsManager
    participant DBus as QDBusConnection
    participant Accounts as org.freedesktop.Accounts

    UserModel->>DAccountsManager: userList()
    DAccountsManager->>DBus: isServiceRegistered(org.freedesktop.Accounts)
    alt service unavailable
        DBus-->>DAccountsManager: false
        DAccountsManager-->>UserModel: DUnexpected ServiceUnknown
    else service available
        DBus-->>DAccountsManager: true
        DAccountsManager->>Accounts: listCachedUsers()
        DAccountsManager->>Accounts: waitForFinished()
        alt reply.isError() or !reply.isValid()
            Accounts-->>DAccountsManager: error reply
            DAccountsManager-->>UserModel: DUnexpected reply error
        else valid reply
            Accounts-->>DAccountsManager: QList<QDBusObjectPath>
            DAccountsManager->>DAccountsManager: getUIDFromObjectPath(user.path())
            DAccountsManager-->>UserModel: QList<quint64>
        end
    end
Loading

File-Level Changes

Change Details Files
Adds defensive handling for unavailable or malformed Accounts D-Bus responses before constructing the user list.
  • Checks whether org.freedesktop.Accounts is registered before issuing the request and returns ServiceUnknown when unavailable.
  • Treats both D-Bus errors and invalid replies as failures.
  • Copies the reply value before iteration and skips entries with empty object paths to avoid null/failed-demarshalling crashes.
src/accounts/daccountsmanager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@zccrs

zccrs commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

Closed in favor of linuxdeepin/dtksystemsettings#148 — dtk6 will auto-sync from main repo.

@zccrs zccrs closed this Aug 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants