Skip to content

fix: fix 3 defects in DriverControl module - #854

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix/v-6205-drivercontrol-defects
Oct 26, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix/v-6205-drivercontrol-defects

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

Root Cause Analysis

Three independent source defects were identified in the DriverControl module during unit testing (baseline f2d46ee9):

  1. checkDriverInfo selection logic (HttpDriverInterface.cpp:219-236): The if (index == 0) branch used index=0 to mean both "not found" and "element 0 selected", causing redundant packageInstall() calls (apt policy subprocess) on every loop iteration. When all max-level candidates were uninstalled, index silently fell back to element 0, overriding the optimal-level selection.

  2. apt policy parse guard too strict (DriverScanner.cpp:56): Guard size() > (2 + index) required 3 lines but only consumed infoList[1 + index] (2 lines), causing valid 2-line apt policy output to be skipped, resulting in empty version numbers.

  3. mkpath failure silently swallowed (DriverBackupThread.cpp:49-51): mkpath failure only logged a message without stopping execution, causing downstream apt download to target a non-existent directory.

Fix

  1. Introduced a bool found flag in checkDriverInfo, break on first installed max-level candidate, and added a fallback loop selecting the first max-level element when none are installed. Removed the redundant if (index == 0) branch.

  2. Changed guard from size() > (2 + index) to size() > (1 + index) in both DriverScanner.cpp:56 and HttpDriverInterface.cpp:288 (same-source guard).

  3. On mkpath failure: emit backupProgressFinished(false) and return, with log level upgraded from qCInfo to qCWarning.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • This fix is a low-risk local change (boundary check fix, local variable adjustment, early return addition). No function signatures changed, no public APIs modified.
  • All three fixes follow existing error-handling patterns in their respective functions.

Business Impact Scope

  • Driver install with multiple candidates: checkDriverInfo now correctly selects the first installed max-level driver candidate, eliminating redundant apt policy subprocess calls.
  • Driver version detection: apt policy parsing now correctly handles 2-line output, ensuring version numbers are populated.
  • Driver backup: mkpath failure now properly aborts backup with a clear error signal instead of proceeding to a guaranteed failure.

Verification Suggestion

  1. Test driver installation with multiple candidates of different levels to verify correct selection.
  2. Test apt policy output with exactly 2 lines (package name + Installed line) to verify version parsing.
  3. Test backup flow when temp directory creation fails to verify proper error signal.

根因分析

单元测试(基线 f2d46ee9)中发现 DriverControl 模块 3 处独立源码缺陷:

  1. checkDriverInfo 选型逻辑(HttpDriverInterface.cpp:219-236):if (index == 0) 分支用 index=0 同时表示"未找到"和"选中元素0",导致每轮循环冗余调用 packageInstall()(apt policy 子进程)。所有 max 等级候选未安装时 index 静默回退元素 0,最优等级判定失效。

  2. apt policy 解析守卫过严(DriverScanner.cpp:56):守卫 size() > (2 + index) 要求 3 行但仅消费 infoList[1 + index](2 行),2 行有效输出被跳过,版本号为空。

  3. mkpath 失败错误被吞(DriverBackupThread.cpp:49-51):mkpath 失败仅记日志不中止,后续 apt download 指向不存在目录注定失败。

修复方案

  1. 引入 bool found 标志位,命中即 break,未命中时回退循环选中第一个 max 等级元素。删除冗余 if (index == 0) 分支。

  2. 守卫改为 size() > (1 + index),同步修复 HttpDriverInterface.cpp:288 同源守卫。

  3. mkpath 失败时 emit backupProgressFinished(false) 并 return,日志级别从 qCInfo 提升至 qCWarning。

改动安全评估

代码安全评估

  • 风险等级: 低风险
  • 本次修复为低风险局部改动(边界检查修正、局部变量调整、提前返回),未修改函数签名,未修改公开 API。
  • 三处修复均遵循各自函数中已有的错误处理模式。

业务影响范围

  • 多候选驱动安装:checkDriverInfo 现正确选中第一个已安装的 max 等级候选,消除冗余 apt policy 子进程调用。
  • 驱动版本检测:apt policy 解析现正确处理 2 行输出,确保版本号正确填充。
  • 驱动备份:mkpath 失败现正确中止备份并发出明确错误信号,而非继续执行注定失败的操作。

验证建议

  1. 测试多候选不同等级的驱动安装场景,验证选型正确性。
  2. 测试 apt policy 输出仅 2 行(包名+Installed 行)的情况,验证版本解析。
  3. 测试临时目录创建失败时的备份流程,验证错误信号。

Summary by Sourcery

Fix DriverControl candidate selection, version detection, and backup error handling.

Bug Fixes:

  • Correct driver candidate selection to choose an installed highest-level candidate without redundant installation checks.
  • Fix driver version parsing for valid two-line package policy output.
  • Abort driver backups and report failure when the destination directory cannot be created.

Chores:

  • Update SPDX copyright ranges for the modified DriverControl sources.

@sourcery-ai

sourcery-ai Bot commented Oct 22, 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 5 days and 12 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026

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

Reviewer's Guide

This low-risk fix addresses three independent DriverControl defects: it makes maximum-level driver selection deterministic and efficient, parses two-line apt policy output correctly in both code paths, and aborts backup cleanly when the destination directory cannot be created.

Sequence diagram for failed driver backup setup

sequenceDiagram
    participant Backup as DriverBackupThread
    participant FS as QDir
    participant Controller as BackupController

    Backup->>FS: mkpath(backupPath)
    alt directory creation succeeds
        Backup->>Backup: apt download
    else directory creation fails
        Backup-->>Controller: backupProgressFinished(false)
        Backup-->>Backup: return
    end
Loading

Flow diagram for deterministic maximum-level driver selection

flowchart TD
    A[Candidate drivers] --> B[Find maximum level]
    B --> C{Installed max-level candidate?}
    C -->|Yes| D["packageInstall(package_name, deb_version)"]
    D --> E[Select first installed candidate]
    C -->|No| F[Select first max-level candidate]
    E --> G[Continue installation flow]
    F --> G
Loading

Flow diagram for two-line apt policy parsing

flowchart TD
    A[apt policy output] --> B{"infoList.size() > 1 + index"}
    B -->|Yes| C["Parse infoList[1 + index]"]
    C --> D[Populate current version]
    B -->|No| E[Version not found]
Loading

File-Level Changes

Change Details Files
Corrected driver candidate selection to distinguish “not found” from index zero and avoid repeated installation checks.
  • Tracks whether an installed maximum-level candidate was found and stops at the first match.
  • Falls back to the first maximum-level candidate when none are installed.
  • Removes the ambiguous index-zero conditional that triggered redundant package checks.
deepin-devicemanager/src/DriverControl/HttpDriverInterface.cpp
Relaxed apt policy output validation so valid two-line responses are parsed.
  • Adjusts both boundary checks to validate the line actually consumed.
  • Preserves existing unexpected-format filtering and version extraction.
deepin-devicemanager/src/DriverControl/DriverScanner.cpp
deepin-devicemanager/src/DriverControl/HttpDriverInterface.cpp
Made backup setup failure terminal and observable.
  • Upgrades the directory-creation failure log to a warning.
  • Emits backupProgressFinished(false) and returns before attempting downloads.
deepin-devicemanager/src/DriverControl/DriverBackupThread.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

1. Root cause: checkDriverInfo used index==0 to mean both "not found"
   and "element 0 selected", causing redundant packageInstall calls and
   fallback to non-max-level element when all max-level candidates
   were uninstalled
2. Fix: introduce bool found flag, break on first installed max-level
   candidate, fallback loop selects first max-level element when none
   installed
3. Root cause: apt policy parse guard size()>(2+index) required 3 lines
   but only consumed 2 lines, skipping valid 2-line output
4. Fix: change guard to size()>(1+index) in DriverScanner.cpp and
   matching size()<=(1+index) in HttpDriverInterface.cpp
5. Root cause: mkpath failure only logged without stopping, causing
   downstream apt download to fail on non-existent directory
6. Fix: emit backupProgressFinished(false) and return on mkpath failure

Influence:
1. Test driver install with multiple candidates of different levels
2. Test apt policy output with exactly 2 lines (package + Installed)
3. Test backup when temp directory creation fails

fix: 修复DriverControl模块3处缺陷

1. 根因:checkDriverInfo中index==0同时表示"未找到"和"选中元素0",
   导致冗余调用packageInstall且所有max等级候选未安装时回退非max元素
2. 方案:引入bool found标志位,命中即break,未命中时回退循环选
   中第一个max等级元素
3. 根因:apt policy解析守卫size()>(2+index)要求3行但仅消费2行,
   2行有效输出被跳过导致版本号为空
4. 方案:DriverScanner.cpp守卫改为>(1+index),HttpDriverInterface.cpp
   同源守卫改为<=(1+index)
5. 根因:mkpath失败仅记日志不中止,后续apt download指向不存在目录
6. 方案:mkpath失败时emit backupProgressFinished(false)并return

Influence:
1. 测试多候选不同等级的驱动安装场景
2. 测试apt policy输出仅2行(包名+Installed行)的情况
3. 测试临时目录创建失败时的备份流程
@add-uos
add-uos force-pushed the fix/v-6205-drivercontrol-defects branch from 3e765f4 to 4d8ad01 Compare October 24, 2026 07:55
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了DriverControl模块中的3个缺陷,涉及DriverBackupThread目录创建失败处理、DriverScanner和HttpDriverInterface的数组越界边界检查修正、以及HttpDriverInterface驱动选择逻辑优化。四维度均无问题,代码质量良好。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: []


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例


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

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@add-uos

add-uos commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
deepin-bot Bot merged commit 8ac6b15 into linuxdeepin:master Oct 26, 2026
17 checks passed
deepin-bot Bot pushed a commit that referenced this pull request Oct 26, 2026
…dling

After the checkDriverInfo fix (PR #854), packageInstall is only
consulted for candidates at the best level, and the redundant
index==0 fallback path was removed. Three checkDriverInfo test
fixtures omitted the "level" field, so the uninitialized
RepoDriverInfo::iLevel decided the outcome: checkDriverInfo_canUpdate
only passed through the removed fallback path and now fails with
stack-garbage levels.

Set an explicit level in those fixtures and pin the package
selection of the not-installed fallback path. All 104 DriverControl
tests pass against the fixed code.
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