Skip to content

fix: correct p2p filter in isValidLogicalName - #762

Open
pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/pms-bug-bot/e2d3468df8a4
Open

pengfeixx wants to merge 1 commit into
linuxdeepin:masterfrom
pengfeixx:agent/pms-bug-bot/e2d3468df8a4

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Root Cause Analysis

isValidLogicalName() in DeviceGenerator.cpp used contains("p2p") to filter P2P wireless interfaces. On arm64 platforms, PCI domain-encoded interface names like enP2p1s0u2 falsely match this filter, causing USB netcards to be excluded from the network adapter list.

Fix

Changed contains("p2p") to startsWith("p2p") so only interface names starting with p2p (e.g., p2p0, p2p1) are filtered. This preserves the original filtering intent while eliminating false matches on arm64 PCI domain-encoded names.

Change Safety Assessment

Code Safety

  • Risk Level: Low
  • The contains("p2p")startsWith("p2p") change is a minimal, targeted fix. P2P interface names always start with p2p, so startsWith fully covers the original filtering intent.
  • No other callers or code paths are affected.

Business Impact

  • Affected module: Network adapter detection in device manager
  • On arm64 platforms with PCI domain=2, USB netcards (e.g., RTL8153) will now correctly appear in the network adapter list
  • No regression risk for existing P2P wireless interface filtering

Verification Suggestion

  • Verify P2P wireless interfaces (e.g., p2p0) are still filtered out
  • Verify arm64 USB netcard interfaces (e.g., enP2p1s0u2) are no longer filtered out
  • Check network adapter list displays correctly on arm64 platform

根因分析

DeviceGenerator.cppisValidLogicalName() 使用 contains("p2p") 过滤 P2P 无线接口。在 arm64 平台上,PCI domain 编码的接口名(如 enP2p1s0u2)会误命中此过滤,导致 USB 网卡被排除在网络适配器列表外。

修复方案

contains("p2p") 改为 startsWith("p2p"),仅过滤以 p2p 开头的接口名(如 p2p0p2p1),保留原有过滤意图,消除 arm64 平台误过滤问题。

改动安全评估

代码安全

  • 风险等级:低
  • contains("p2p")startsWith("p2p") 是最小化定向修复,P2P 接口名均以 p2p 开头,startsWith 完全覆盖原有过滤意图
  • 不影响其他调用者或代码路径

业务影响范围

  • 受影响模块:设备管理器网络适配器检测
  • arm64 平台 PCI domain=2 的 USB 网卡(如 RTL8153)将正确显示在网络适配器列表中
  • 对现有 P2P 无线接口过滤无回归风险

验证建议

  • 验证 P2P 无线接口(如 p2p0)仍被正确过滤
  • 验证 arm64 USB 网卡接口(如 enP2p1s0u2)不再被误过滤
  • 检查 arm64 平台网络适配器列表显示正常

PMS: 239527

Summary by Sourcery

Bug Fixes:

  • Prevent valid network interfaces whose names contain “p2p” from being incorrectly excluded while continuing to filter P2P interfaces.

1. Root cause: isValidLogicalName() used contains("p2p") to
   filter P2P wireless interfaces, which incorrectly matched
   arm64 PCI domain-encoded interface names like enP2p1s0u2
2. Solution: change contains() to startsWith() so only interface
   names starting with "p2p" (e.g. p2p0, p2p1) are filtered
3. Impact: arm64 USB netcards with PCI domain=2 no longer get
   falsely filtered out from the network adapter list

fix: 修正 isValidLogicalName 中 p2p 过滤逻辑

1. 根因:isValidLogicalName() 使用 contains("p2p") 过滤 P2P
   无线接口,导致 arm64 平台 PCI domain 编码的接口名(如
   enP2p1s0u2)被误过滤
2. 解决方案:将 contains() 改为 startsWith(),仅过滤以
   "p2p" 开头的接口名(如 p2p0、p2p1)
3. 影响:arm64 平台 PCI domain=2 的 USB 网卡不再被误过滤,
   可正确显示在网络适配器列表中

PMS: 239527

@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.

Sorry @pengfeixx, 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 10 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: pengfeixx

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 Sep 16, 2026

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

Reviewer's Guide

Updates logical-name validation to filter only interfaces whose names start with “p2p”, preserving P2P filtering while allowing arm64 PCI domain-encoded USB network interfaces to appear in the adapter list.

Flow diagram for logical network interface validation

flowchart TD
    A["Network interface logical name"] --> B{"isValidLogicalName"}
    B --> C{"Starts with p2p?"}
    C -->|Yes| D["Reject P2P interface"]
    C -->|No| E{"Name is empty?"}
    E -->|Yes| F["Reject interface"]
    E -->|No| G["Accept for adapter list"]
Loading

File-Level Changes

Change Details Files
Restrict P2P interface filtering to names with the expected prefix, preventing false exclusions of PCI domain-encoded interfaces.
  • Replace case-insensitive substring matching with case-insensitive prefix matching.
  • Continue rejecting empty logical names and genuine interfaces such as p2p0/p2p1.
  • Allow names such as enP2p1s0u2 to proceed through network adapter detection.
deepin-devicemanager/src/GenerateDevice/DeviceGenerator.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 代码审查报告

PR: linuxdeepin/deepin-devicemanager#762
标题: fix: correct p2p filter in isValidLogicalName
作者: pengfeixx
审查模式: 全量分析(GitHub PR)
审查时间: 2026-09-17 02:20:00


总体评价

总分: 98/100 | 等级: 优秀 | 风险等级: None

代码审查通过。本次变更是一个精准的 Bug 修复,将 isValidLogicalName 函数中的 contains("p2p") 改为 startsWith("p2p"),正确过滤以 p2p 开头的接口名,避免误过滤 arm64 平台 PCI domain 编码的接口名(如 enP2p1s0u2)。未发现安全漏洞,代码逻辑正确,性能良好。


漏洞统计

指标 数量
当前漏洞总数 0
新增漏洞 0
修复漏洞 0
持平漏洞 0

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个


四维度评分

维度1:语法逻辑(25/25分)✓

语法正确,逻辑清晰

分析:

  • startsWithQString 类的合法方法,调用语法正确
  • 逻辑变更合理:startsWith("p2p") 仅匹配以 "p2p" 开头的接口名(如 p2p0p2p1),而 contains("p2p") 会误匹配任何包含 "p2p" 子串的接口名(如 enP2p1s0u2
  • 函数整体逻辑完整:先过滤无效名称(p2p 开头或空字符串),再通过 QDir::exists() 验证接口在 /sys/class/net/ 下的存在性
  • 无编译错误,无逻辑缺陷,边界条件处理完善

无问题


维度2:代码质量(23/25分)✓

代码结构清晰,注释完整

分析:

  • 函数名 isValidLogicalName 语义清晰,自解释性强
  • 函数职责单一,仅做接口名合法性校验
  • 无代码重复,无残留调试代码
  • qCInfo 日志输出合理,记录不存在的路径信息,非敏感信息

问题列表:

  1. 轻微:函数 isValidLogicalName(第318行)无文档注释,虽然函数名已自解释,但建议添加简短注释说明过滤规则(-2分)

改进建议:

// 校验网络接口逻辑名是否有效
// 过滤规则:排除以 "p2p" 开头的 P2P 无线接口和空字符串,
// 并验证接口在 /sys/class/net/ 下存在
bool isValidLogicalName(const QString& logicalName)
{
    if (logicalName.startsWith("p2p", Qt::CaseInsensitive) || logicalName.isEmpty())
        return false;
    // ...
}

维度3:代码性能(20/20分)✓

性能良好,资源使用合理

分析:

  • startsWith 操作复杂度为 O(k),k 为搜索字符串长度(3字符),效率极高
  • QDir::exists() 文件系统检查是必要的验证步骤,且仅在名称校验通过后执行
  • 无频繁系统调用,无不必要的内存操作
  • 无性能瓶颈

无问题


维度4:代码安全(30/30分)✓

存在0个安全漏洞

分析:

  • 安全扫描工具(security_scanner.py)扫描结果:0 个安全漏洞
  • OCR 审查:因 LLM 配置问题未成功执行,无补充结果
  • 本次变更(containsstartsWith)未引入任何新的安全风险
  • 路径拼接 /sys/class/net/" + logicalName 为已有代码,logicalName 来源于系统命令(lshw/hwinfo)输出,非直接用户输入
  • 变更缩小了过滤范围,不影响安全性

安全漏洞清单: 无


代码变更详情

文件: deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp
函数: isValidLogicalName(第318-330行)

 bool isValidLogicalName(const QString& logicalName)
 {
-    if (logicalName.contains("p2p", Qt::CaseInsensitive) || logicalName.isEmpty())
+    if (logicalName.startsWith("p2p", Qt::CaseInsensitive) || logicalName.isEmpty())
         return false;
 
     QString addressFilePath = "/sys/class/net/" + logicalName;

变更说明:

  • contains("p2p") 改为 startsWith("p2p")
  • contains 会匹配任何包含 "p2p" 子串的接口名,导致 arm64 平台 PCI domain 编码的接口名(如 enP2p1s0u2)被误过滤
  • startsWith 仅匹配以 "p2p" 开头的接口名(如 p2p0p2p1),精准过滤 P2P 无线接口

审查结论

本次代码变更是一个精准、最小化的 Bug 修复,符合 commit message 中描述的修复目的。将 contains("p2p") 改为 startsWith("p2p") 正确解决了 arm64 平台 USB 网卡被误过滤的问题。代码逻辑正确,无安全漏洞,性能无影响,建议合并。

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