Skip to content

fix: validate DBus reply in SMB mount path - #413

Closed
Johnson-zs wants to merge 1 commit into
linuxdeepin:masterfrom
Johnson-zs:agent/bug/eea5e20d2ece
Closed

Johnson-zs wants to merge 1 commit into
linuxdeepin:masterfrom
Johnson-zs:agent/bug/eea5e20d2ece

Conversation

@Johnson-zs

ghost commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

fix: validate DBus reply in SMB mount path

  1. Root cause: mountWithUserInput() and mountWithSavedInfos() did not
    check QDBusReply validity, DBus timeout produced contradictory state
    ok=false with err=kNoError, triggering false error dialog
  2. Fix: add ret.isValid() guard before accessing reply value, on
    NoReply timeout use isMounted() to verify actual mount status,
    increase DBus timeout from 25s to 60s for slow SMB networks
  3. Impact: eliminates false mount-failure dialog when SMB mount succeeds
    but DBus call times out, normal path unchanged

Log: fix false mount error dialog on SMB DBus timeout

Influence:

  1. Test SMB mount with correct credentials, verify no false error
  2. Test SMB mount under slow network to trigger DBus timeout
  3. Verify mount-failure dialog still shows on genuine mount failures

fix: 修复SMB挂载DBus超时误报错误对话框

  1. 根因:mountWithUserInput()和mountWithSavedInfos()未校验DBus回复
    有效性,DBus超时产生矛盾状态ok=false且err=kNoError,误弹错误对话框
  2. 方案:访问回复值前增加ret.isValid()检查,NoReply超时时通过
    isMounted()查询实际挂载状态,DBus超时从25秒增至60秒
  3. 影响:消除SMB挂载成功但DBus超时时的误报错误对话框,正常路径无变化

Log: 修复SMB挂载DBus超时时的误报错误对话框

Influence:

  1. 测试使用正确凭据SMB挂载,验证无误报错误对话框
  2. 测试慢网络下SMB挂载触发DBus超时场景
  3. 验证真实挂载失败仍正确显示错误对话框

PMS: BUG-295741

Summary by Sourcery

Make SMB mount handling resilient to DBus timeouts by validating replies and confirming the actual mount state before reporting failure.

Bug Fixes:

  • Prevent false SMB mount-failure reports when DBus calls time out after the mount has succeeded.
  • Handle invalid DBus mount replies safely and preserve genuine failure reporting.

Enhancements:

  • Increase the SMB mount DBus timeout to better accommodate slow networks and verify mount status after no-reply timeouts.

1. Root cause: mountWithUserInput() and mountWithSavedInfos() did not
   check QDBusReply validity, DBus timeout produced contradictory state
   ok=false with err=kNoError, triggering false error dialog
2. Fix: add ret.isValid() guard before accessing reply value, on
   NoReply timeout use isMounted() to verify actual mount status,
   increase DBus timeout from 25s to 60s for slow SMB networks
3. Impact: eliminates false mount-failure dialog when SMB mount succeeds
   but DBus call times out, normal path unchanged

Log: fix false mount error dialog on SMB DBus timeout

Influence:
1. Test SMB mount with correct credentials, verify no false error
2. Test SMB mount under slow network to trigger DBus timeout
3. Verify mount-failure dialog still shows on genuine mount failures

fix: 修复SMB挂载DBus超时误报错误对话框

1. 根因:mountWithUserInput()和mountWithSavedInfos()未校验DBus回复
   有效性,DBus超时产生矛盾状态ok=false且err=kNoError,误弹错误对话框
2. 方案:访问回复值前增加ret.isValid()检查,NoReply超时时通过
   isMounted()查询实际挂载状态,DBus超时从25秒增至60秒
3. 影响:消除SMB挂载成功但DBus超时时的误报错误对话框,正常路径无变化

Log: 修复SMB挂载DBus超时时的误报错误对话框

Influence:
1. 测试使用正确凭据SMB挂载,验证无误报错误对话框
2. 测试慢网络下SMB挂载触发DBus超时场景
3. 验证真实挂载失败仍正确显示错误对话框

PMS: BUG-295741
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs

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 Oct 29, 2026

Copy link
Copy Markdown

Reviewer's Guide

The SMB mount paths now validate QDBusReply results before accessing returned data, treat NoReply timeouts as recoverable by verifying the actual mount state, and allow up to 60 seconds for slow DBus-backed SMB mounts, preventing false failure dialogs when the mount succeeds.

Sequence diagram for resilient SMB mount DBus handling

sequenceDiagram
    participant Caller
    participant Mounter
    participant DBus as MountControlDBus
    participant System as MountState

    Caller->>Mounter: mountWithUserInput()
    Mounter->>DBus: call(kMountControlMount, address, param)
    Note over DBus: Timeout set to 60000 ms
    DBus-->>Mounter: QDBusReply<QVariantMap>
    alt ret.isValid()
        Mounter->>Mounter: ret.value()
        Mounter-->>Caller: MountRet from DBus reply
    else NoReply timeout
        Mounter->>System: isMounted(address, checkMpt)
        alt Mount is present
            System-->>Mounter: true, checkMpt
            Mounter-->>Caller: success with mount point
        else Mount is absent
            System-->>Mounter: false
            Mounter-->>Caller: kGDBusErrorNoReply
        end
    else Other invalid reply
        Mounter-->>Caller: kGDBusErrorNoReply
    end
Loading

File-Level Changes

Change Details Files
Validate DBus mount replies before reading their payload and distinguish timeout handling from other reply failures.
  • Added validity checks for mount-control DBus replies in both user-input and saved-information flows.
  • Mapped invalid replies to DBus errors instead of processing empty or contradictory result data.
src/dfm-mount/private/dnetworkmounter.cpp
Recover from DBus no-reply timeouts by checking the actual filesystem mount state.
  • Queries isMounted() after a NoReply response and reports success when the SMB mount completed despite the timeout.
  • Returns a specific no-reply failure for the user-input path and exits the saved-information retry flow when the mount is not present.
src/dfm-mount/private/dnetworkmounter.cpp
Increase the mount-control DBus call timeout to accommodate slow SMB networks.
  • Sets the DBus interface timeout to 60 seconds for user-input mounts.
src/dfm-mount/private/dnetworkmounter.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 ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 94 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 SMB 挂载路径添加了 DBus 回复校验逻辑,核心修复正确有效:设置了 60 秒超时、校验回复有效性、对 NoReply 错误通过 isMounted() 进行优雅降级处理。 四维度均通过,仅存在错误码映射不够精确和少量代码重复的轻微问题,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 边界处理完善 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['对于非 NoReply 的 DBus 错误,建议映射到更精确的 DeviceError 枚举值(如 kGDBusErrorFailed),而非统一使用 kGDBusErrorNoReply', '在 mountWithSavedInfos 中,非 NoReply 错误建议直接返回错误而非 break,避免误导性地提示用户输入登录凭据']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['建议将 NoReply 错误处理逻辑(判断错误类型、调用 isMounted、返回结果)提取为公共辅助函数,减少重复代码']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 建议改进:非 NoReply 错误使用更精确的错误码,并提取公共处理逻辑

// 提取公共的 NoReply 错误处理函数
std::optional<DNetworkMounter::MountRet> handleDBusNoReply(const QString &address,
                                                            DNetworkMounter *mounter)
{
    QString checkMpt;
    if (mounter->isMounted(address, checkMpt))
        return DNetworkMounter::MountRet{true, DeviceError::kNoError, checkMpt};
    return DNetworkMounter::MountRet{false, DeviceError::kGDBusErrorNoReply, ""};
}

// 在 mountWithUserInput 中:
if (!ret.isValid()) {
    const auto &e = ret.error();
    if (e.type() == QDBusError::NoReply
        || e.name() == QStringLiteral("org.freedesktop.DBus.Error.NoReply")) {
        auto result = handleDBusNoReply(address, this);
        if (result)
            return *result;
        return {false, DeviceError::kGDBusErrorNoReply, ""};
    }
    // 非 NoReply 错误使用通用错误码
    return {false, DeviceError::kGDBusErrorFailed, ""};
}

本报告由 AI 代码审查工具自动生成

@Johnson-zs Johnson-zs closed this Oct 29, 2026
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.

2 participants