Skip to content

fix: resolve 7 defects in devicemanager source code - #882

Open
add-uos wants to merge 2 commits into
linuxdeepin:masterfrom
add-uos:agent/bug/e89ba042f2dd
Open

add-uos wants to merge 2 commits into
linuxdeepin:masterfrom
add-uos:agent/bug/e89ba042f2dd

Conversation

@add-uos

@add-uos add-uos commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

fix: resolve 7 defects in devicemanager source code

  1. D1: networkIsOnline Qt6 branch used == instead of != for
    Disconnected check, returning true when offline (inverted)
  2. D2: slotInstallProgressFinished called removeAt(indexOf())
    without checking -1, causing out-of-bounds removal
  3. D3: setCheckedCBDisable dereferenced mp_HeaderCb without
    null check, crashing when header checkbox not initialized
  4. D4: setTimeout(1000*1000) set 1000s timeout on DBus calls,
    blocking when service unavailable; restored to default (-1)
  5. D5: destructor used deleteLater on child layout after
    DELETE_PTR on parent, causing use-after-free
  6. D6: slotClose emitted refreshInfo and called close, triggering
    closeEvent which re-entered slotClose causing duplicate refresh
  7. D7: isRunning matched objectName "PageDriverControlWindow"
    which no code sets, making running check always false

Log: Fixed multiple crash, hang, and logic defects in device manager

Influence:

  1. Test network status detection under online and offline conditions
  2. Test driver installation progress and index list management
  3. Test checkbox operations when header is not initialized
  4. Test DBus calls when driver service is unavailable
  5. Test window close during driver processing states

fix: 修复设备管理器7项源码缺陷

  1. D1:networkIsOnline Qt6分支使用==而非!=判断Disconnected,
    导致断网时返回true(逻辑反置)
  2. D2:slotInstallProgressFinished中removeAt(indexOf())未检查-1,
    索引不存在时越界删除
  3. D3:setCheckedCBDisable未判空直接解引用mp_HeaderCb,
    表头复选框未初始化时崩溃
  4. D4:setTimeout(1000*1000)设置1000秒超时,服务缺失时阻塞;
    恢复为默认超时(-1)
  5. D5:析构函数先DELETE_PTR父布局再deleteLater子布局,
    导致use-after-free
  6. D6:slotClose同时emit refreshInfo和close,触发closeEvent
    重入slotClose导致重复刷新
  7. D7:isRunning匹配objectName "PageDriverControlWindow"全工程
    无人设置,运行状态检查永远返回false

Log: 修复设备管理器多处崩溃、卡死和逻辑缺陷

Influence:

  1. 测试联网和断网状态下的网络状态检测
  2. 测试驱动安装进度和索引列表管理
  3. 测试表头未初始化时的复选框操作
  4. 测试驱动服务不可用时的DBus调用
  5. 测试驱动处理各状态下的窗口关闭操作

PMS: BUG-7

Summary by Sourcery

Bug Fixes:

  • Correct network reachability reporting, installation-progress index handling, uninitialized header-checkbox access, DBus call timeouts, widget destruction, close-event refresh behavior, and driver-control running-state detection.

@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 20 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

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 23, 2026

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

Reviewer's Guide

The PR resolves seven device-manager defects across DBus communication, driver installation state tracking, window close handling, widget destruction, and checkbox safety. The changes restore default DBus timeouts, correct online detection and running-window identification, guard invalid list and null-pointer access, and eliminate close-event refresh re-entry and layout use-after-free risks.

Sequence diagram for safe driver window closing and refresh

sequenceDiagram
    participant User
    participant PageDriverControl
    participant closeEvent
    participant DeviceManager

    User->>PageDriverControl: close()
    PageDriverControl->>closeEvent: closeEvent()
    alt DriverProcessStatus is Done
        closeEvent->>DeviceManager: refreshInfo()
    else Processing state
        closeEvent-->>PageDriverControl: keep window open
    end
Loading

Sequence diagram for bounded DBus driver operations

sequenceDiagram
    participant PageDriverManager
    participant DBusDriverInterface
    participant DBusService

    PageDriverManager->>DBusDriverInterface: installDriverFd()
    DBusDriverInterface->>DBusDriverInterface: setTimeout(-1)
    DBusDriverInterface->>DBusService: asyncCall(installDriverFd)
    DBusService-->>DBusDriverInterface: finished()
    DBusDriverInterface-->>PageDriverManager: operation result
Loading

Flow diagram for corrected driver installation state handling

flowchart TD
    A[Installation succeeds] --> B[indexOf current driver]
    B --> C{Index found}
    C -->|Yes| D[removeAt index]
    C -->|No| E[Keep list unchanged]
Loading

File-Level Changes

Change Details Files
Corrected DBus timeout configuration to avoid excessive blocking while preserving the default service-call timeout.
  • Reset uninstall, driver-install, and package-backup calls to the default DBus timeout.
deepin-devicemanager/src/DriverControl/DBusDriverInterface.cpp
Fixed driver-control window lifecycle and state detection issues, including close-event re-entry and invalid running-window identification.
  • Matched the running window using the object name assigned by the implementation.
  • Moved refresh signaling into close-event handling for completed processes.
  • Removed the duplicate refresh emission from the close slot.
deepin-devicemanager/src/Page/PageDriverControl.cpp
Hardened driver installation progress bookkeeping and corrected Qt6 network reachability logic.
  • Guarded list removal when the current index is absent.
  • Reported online status for every reachability state except Disconnected.
deepin-devicemanager/src/Page/PageDriverManager.cpp
Made detected-status widget destruction safe by consistently deleting the affected layout synchronously.
  • Replaced deferred deletion of the label layout with the existing ownership-safe deletion macro.
deepin-devicemanager/src/Widget/DetectedStatusWidget.cpp
Prevented checkbox operations from dereferencing an uninitialized header checkbox.
  • Added a null check before reading or disabling the header checkbox.
deepin-devicemanager/src/Widget/drivertableview.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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本PR主要包含多项Bug修复与代码改进:修复了networkIsOnline的网络状态判断逻辑反转错误(==改为!=)、 修复了窗口对象名称不匹配问题、增加了removeAt前的indexOf越界检查和mp_HeaderCb空指针检查、 统一了析构函数中DELETE_PTR宏的使用、重构了closeEvent与slotClose以避免潜在递归调用。 代码安全维度无漏洞,代码质量与性能维度表现良好。语法逻辑维度存在一处一般错误: DBusDriverInterface中将setTimeout从1000*1000(1000秒)改为-1(默认25秒), 但代码注释明确指出打印卸载约需30秒、备份需拷贝整个目录,-1超时可能短于实际操作时间, 尤其backupDebFd使用同步call()可能导致备份失败。建议设置更合理的超时值如60000ms。

🔍 详细分析

1. 语法逻辑 ❌

评价: 存在逻辑缺陷 ❌ 不通过

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

建议: ['建议将setTimeout设置为更合理的值,如60000(60秒)或120000(120秒), 既避免1000秒过长等待,又确保不短于实际操作时间。例如: mp_Iface->setTimeout(60000);']


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// DBusDriverInterface.cpp - 建议使用合理的超时值 // 替代 setTimeout(-1),避免超时短于操作时间
void DBusDriverInterface::uninstallPrinter(const QString &vendor, const QString &model) {
    qCDebug(appLog) << "Uninstall printer - vendor:" << vendor << "model:" << model;
    // 设置60秒超时,既避免1000秒过长等待,又确保不短于打印卸载的30秒
    mp_Iface->setTimeout(60000);
    QDBusPendingCall async = mp_Iface->asyncCall("unInstallPrinter", vendor, model);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);
    // ...
}
void DBusDriverInterface::backupDebFd(const QDBusUnixFileDescriptor &dirFd, const QString &debname) {
    qCDebug(appLog) << "DBusDriverInterface::backupDebFd, debname:" << debname;
    // 备份需拷贝整个暂存目录,设置120秒超时
    mp_Iface->setTimeout(120000);
    QDBusReply<bool> reply = mp_Iface->call("backupDebFd", QVariant::fromValue(dirFd), debname);
    // ...
}

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

1. D1: networkIsOnline Qt6 branch used == instead of != for
   Disconnected check, returning true when offline (inverted)
2. D2: slotInstallProgressFinished called removeAt(indexOf())
   without checking -1, causing out-of-bounds removal
3. D3: setCheckedCBDisable dereferenced mp_HeaderCb without
   null check, crashing when header checkbox not initialized
4. D4: setTimeout(1000*1000) set 1000s timeout on DBus calls,
   blocking when service unavailable; restored to default (-1)
5. D5: destructor used deleteLater on child layout after
   DELETE_PTR on parent, causing use-after-free
6. D6: slotClose emitted refreshInfo and called close, triggering
   closeEvent which re-entered slotClose causing duplicate refresh
7. D7: isRunning matched objectName "PageDriverControlWindow"
   which no code sets, making running check always false

Log: Fixed multiple crash, hang, and logic defects in device manager

Influence:
1. Test network status detection under online and offline conditions
2. Test driver installation progress and index list management
3. Test checkbox operations when header is not initialized
4. Test DBus calls when driver service is unavailable
5. Test window close during driver processing states

fix: 修复设备管理器7项源码缺陷

1. D1:networkIsOnline Qt6分支使用==而非!=判断Disconnected,
   导致断网时返回true(逻辑反置)
2. D2:slotInstallProgressFinished中removeAt(indexOf())未检查-1,
   索引不存在时越界删除
3. D3:setCheckedCBDisable未判空直接解引用mp_HeaderCb,
   表头复选框未初始化时崩溃
4. D4:setTimeout(1000*1000)设置1000秒超时,服务缺失时阻塞;
   恢复为默认超时(-1)
5. D5:析构函数先DELETE_PTR父布局再deleteLater子布局,
   导致use-after-free
6. D6:slotClose同时emit refreshInfo和close,触发closeEvent
   重入slotClose导致重复刷新
7. D7:isRunning匹配objectName "PageDriverControlWindow"全工程
   无人设置,运行状态检查永远返回false

Log: 修复设备管理器多处崩溃、卡死和逻辑缺陷

Influence:
1. 测试联网和断网状态下的网络状态检测
2. 测试驱动安装进度和索引列表管理
3. 测试表头未初始化时的复选框操作
4. 测试驱动服务不可用时的DBus调用
5. 测试驱动处理各状态下的窗口关闭操作

PMS: BUG-7
The license-check CI (SPDX Header Validation) requires files created in
earlier years and modified in 2026 to carry a copyright year range ending
with the current year. Extend the SPDX-FileCopyrightText headers of
PageDriverManager.cpp and drivertableview.cpp from 2022 to 2022-2026 so
the SPDX summary reports 0 failures.
@add-uos
add-uos force-pushed the agent/bug/e89ba042f2dd branch from 1e478bb to f8f48e6 Compare October 27, 2026 03:49
@deepin-bot

deepin-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.75
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #956

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