Skip to content

fix: correct fprintf escapes and add guard - #886

Closed
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/754d9c5db1f4
Closed

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/754d9c5db1f4

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

fix: correct fprintf escapes and add guard

  1. Root cause: fprintf strings in DBusEnableInterface and
    DBusWakeupInterface used /n and /t instead of \n and \t,
    causing error messages to display literal characters
  2. Fix: replace /n with \n and /t with \t in both files; add
    local size() < 2 guard before pathList index access
  3. Impact: error messages now format with proper newlines and
    tabs; bounds guard prevents potential out-of-bounds access

Influence:

  1. Test D-Bus connection failure error message formatting
  2. Test wakeup device path with insufficient path segments
  3. Verify normal D-Bus initialization has no regression

fix: 修正fprintf转义符并增加边界检查

  1. 根因:DBusEnableInterface 和 DBusWakeupInterface 的 fprintf
    误用 /n 和 /t 代替 \n 和 \t,错误提示输出字面量不换行
  2. 方案:将两处 fprintf 中 /n 改为 \n、/t 改为 \t;在
    pathList 索引访问前增加 size() < 2 局部边界校验
  3. 影响:错误提示恢复正常换行和缩进格式;局部边界检查
    防止未来重构移除入口校验后的潜在越界访问

Influence:

  1. 测试 D-Bus 连接失败时的错误提示格式
  2. 测试路径分段不足时的唤醒设备处理
  3. 验证正常 D-Bus 初始化流程无回归

Summary by Sourcery

Fix D-Bus error message formatting and prevent invalid wakeup-device path access.

Bug Fixes:

  • Correct D-Bus connection error messages to render newlines and indentation properly.
  • Guard wakeup-device path handling against insufficient path segments before indexing.

1. Root cause: fprintf strings in DBusEnableInterface and
   DBusWakeupInterface used /n and /t instead of \n and \t,
   causing error messages to display literal characters
2. Fix: replace /n with \n and /t with \t in both files; add
   local size() < 2 guard before pathList index access
3. Impact: error messages now format with proper newlines and
   tabs; bounds guard prevents potential out-of-bounds access

Influence:
1. Test D-Bus connection failure error message formatting
2. Test wakeup device path with insufficient path segments
3. Verify normal D-Bus initialization has no regression

fix: 修正fprintf转义符并增加边界检查

1. 根因:DBusEnableInterface 和 DBusWakeupInterface 的 fprintf
   误用 /n 和 /t 代替 \n 和 \t,错误提示输出字面量不换行
2. 方案:将两处 fprintf 中 /n 改为 \n、/t 改为 \t;在
   pathList 索引访问前增加 size() < 2 局部边界校验
3. 影响:错误提示恢复正常换行和缩进格式;局部边界检查
   防止未来重构移除入口校验后的潜在越界访问

Influence:
1. 测试 D-Bus 连接失败时的错误提示格式
2. 测试路径分段不足时的唤醒设备处理
3. 验证正常 D-Bus 初始化流程无回归
@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.

@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

This PR fixes D-Bus connection error-message formatting by using valid newline and tab escapes, and hardens wakeup-device handling with a local pathList size guard before indexing.

Sequence diagram for guarded wakeup device configuration

sequenceDiagram
    participant Caller
    participant DBusWakeupInterface
    participant InputInterface

    Caller->>DBusWakeupInterface: setWakeupMachine(unique_id, wakeup)
    DBusWakeupInterface->>DBusWakeupInterface: pathList.size()
    alt pathList.size() < 2
        DBusWakeupInterface-->>Caller: return false
    else pathList has at least 2 segments
        DBusWakeupInterface->>InputInterface: call(SetWakeupDevices, busPath, state)
    end
Loading

Flow diagram for formatted D-Bus connection errors

flowchart TD
    A[Initialize D-Bus interface] --> B{"systemBus().isConnected()"}
    B -->|No| C[fprintf error with newline and tab escapes]
    B -->|Yes| D[Create D-Bus interface]
Loading

File-Level Changes

Change Details Files
Correct malformed escape sequences in D-Bus connection diagnostics so stderr output uses actual line breaks and indentation.
  • Replace literal /n and /t sequences with \n and \t in both initialization error messages.
  • Preserve the existing guidance while making the formatted output readable.
deepin-devicemanager/src/EnableControl/DBusEnableInterface.cpp
deepin-devicemanager/src/WakeupControl/DBusWakeupInterface.cpp
Add a local bounds check before deriving the wakeup device path from pathList.
  • Return false when fewer than two path segments are available before indexing pathList.
  • Prevent potential out-of-bounds access during SetWakeupDevices handling.
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

@add-uos

add-uos commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #887 (same fix, same target branch). PR #887 is the one being used for this fix.

@add-uos add-uos closed this Oct 23, 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