Skip to content

fix: correct fprintf escapes and add bounds guard - #887

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/16fb381fa102
Oct 24, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bug/16fb381fa102

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

fix: correct fprintf escapes and add bounds guard

  1. Root cause: fprintf error strings in DBusEnableInterface and
    DBusWakeupInterface used /n and /t instead of \n and \t escape
    sequences, causing error output to not format with newlines or
    indentation
  2. Fix: corrected three fprintf calls to use \n and \t standard C
    escape sequences for proper error message formatting
  3. Root cause: pathList[pathList.size()-2] access lacked a local
    bounds guard, risking out-of-bounds access if entry validation
    is removed or refactored in the future
  4. Fix: added local if (pathList.size() < 2) return false guard
    before the index access as defensive programming

Influence:

  1. Test D-Bus connection failure to verify error output formatting
  2. Test setWakeupMachine with various sysfs path segmentations
  3. Verify normal device wake-up functionality has no regression

fix: 修复fprintf转义错误并增加越界防护

  1. 根因:DBusEnableInterface和DBusWakeupInterface中fprintf
    错误字符串误用/n和/t而非\n和\t转义序列,导致错误输出
    无法正确换行和缩进
  2. 方案:修正三处fprintf调用,使用\n和\t标准C转义序列,
    恢复错误消息的正确格式化
  3. 根因:pathList[pathList.size()-2]索引访问缺少局部越界
    防护,若未来重构移除入口校验将存在越界风险
  4. 方案:在索引访问前增加局部if (pathList.size() < 2)
    return false校验,作为防御性编程措施

Influence:

  1. 测试D-Bus连接失败场景,验证错误输出格式正确
  2. 测试setWakeupMachine在各种sysfs路径分段下的行为
  3. 验证正常设备唤醒功能无回归

PMS: BUG-6206

Summary by Sourcery

Improve D-Bus error reporting and harden wake-up device path validation against malformed paths.

Bug Fixes:

  • Correct D-Bus connection error messages so their line breaks and indentation render properly.
  • Prevent wake-up device path handling from accessing an out-of-bounds path segment.

Chores:

  • Update SPDX copyright years for the modified interface files.

@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 18 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@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 fixes incorrectly escaped D-Bus connection diagnostics and adds a local guard against insufficient sysfs path segments before indexing, with review focus on error-output formatting, invalid-path behavior, and preserving normal device wake-up flow.

Sequence diagram for guarded device wake-up path

sequenceDiagram
    participant Caller
    participant DBusWakeupInterface
    participant InputInterface

    Caller->>DBusWakeupInterface: setWakeupMachine(unique_id, wakeup)
    DBusWakeupInterface->>DBusWakeupInterface: pathList.size()
    alt fewer than 2 path segments
        DBusWakeupInterface-->>Caller: false
    else valid path segments
        DBusWakeupInterface->>InputInterface: call(SetWakeupDevices, busPath, state)
        InputInterface-->>DBusWakeupInterface: result
        DBusWakeupInterface-->>Caller: wake-up result
    end
Loading

File-Level Changes

Change Details Files
Correct malformed fprintf escape sequences so D-Bus connection errors render with proper line breaks and indentation.
  • Replace literal /n and /t text with standard C \n and \t escapes in both initialization error messages.
  • Preserve the existing diagnostic content while restoring readable multi-line output.
deepin-devicemanager/src/EnableControl/DBusEnableInterface.cpp
deepin-devicemanager/src/WakeupControl/DBusWakeupInterface.cpp
Add a local defensive bounds check before deriving the sysfs device path from pathList.
  • Return false when fewer than two path segments are available before accessing pathList[pathList.size() - 2].
  • Keep the existing wake-up D-Bus invocation unchanged for valid paths.
deepin-devicemanager/src/WakeupControl/DBusWakeupInterface.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 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了 fprintf 转义字符错误(/n 改为 \n,/teval 改为 \teval)并添加了数组越界保护, 四维度均无问题,代码安全无漏洞,质量优秀。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 当前代码已正确修复,无需额外修改。 // 边界检查示例(已正确实现): // if (pathList.size() < 2) //     return false; // QString curPath = pathList[pathList.size() - 2];

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

1. Root cause: fprintf error strings in DBusEnableInterface and
   DBusWakeupInterface used /n and /t instead of \n and \t escape
   sequences, causing error output to not format with newlines or
   indentation
2. Fix: corrected three fprintf calls to use \n and \t standard C
   escape sequences for proper error message formatting
3. Root cause: pathList[pathList.size()-2] access lacked a local
   bounds guard, risking out-of-bounds access if entry validation
   is removed or refactored in the future
4. Fix: added local if (pathList.size() < 2) return false guard
   before the index access as defensive programming

Influence:
1. Test D-Bus connection failure to verify error output formatting
2. Test setWakeupMachine with various sysfs path segmentations
3. Verify normal device wake-up functionality has no regression

fix: 修复fprintf转义错误并增加越界防护

1. 根因:DBusEnableInterface和DBusWakeupInterface中fprintf
   错误字符串误用/n和/t而非\n和\t转义序列,导致错误输出
   无法正确换行和缩进
2. 方案:修正三处fprintf调用,使用\n和\t标准C转义序列,
   恢复错误消息的正确格式化
3. 根因:pathList[pathList.size()-2]索引访问缺少局部越界
   防护,若未来重构移除入口校验将存在越界风险
4. 方案:在索引访问前增加局部if (pathList.size() < 2)
   return false校验,作为防御性编程措施

Influence:
1. 测试D-Bus连接失败场景,验证错误输出格式正确
2. 测试setWakeupMachine在各种sysfs路径分段下的行为
3. 验证正常设备唤醒功能无回归

PMS: BUG-6206
@add-uos
add-uos force-pushed the agent/bug/16fb381fa102 branch from b746317 to b599166 Compare October 24, 2026 07:37
@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 24, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 0f1d52e into linuxdeepin:master Oct 24, 2026
16 of 17 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