Repository navigation
fix: strip /sys prefix precisely in isPathExisted - #831
Merged
deepin-bot[bot] merged 1 commit intoOct 10, 2026
Merged
Conversation
1. Root cause: pathT.replace("/sys", "") uses global replace
semantics, deleting all "/sys" substrings in the path instead of
only the leading prefix
2. Fix: replace with startsWith("/sys") + remove(0, 4) to strip only
the leading 4-char prefix, preserving any "/sys" substrings in the
middle of the path
3. Impact: paths with a single leading /sys behave identically; paths
containing multiple /sys substrings are no longer incorrectly
modified; no signature change, no performance impact
Influence:
1. Verify isPathExisted returns correct result for standard /sys paths
2. Verify paths with multiple /sys substrings are handled correctly
3. Verify paths without /sys prefix still work as before
fix: 修复 isPathExisted 中 /sys 前缀剥离使用全局替换的问题
1. 根因:pathT.replace("/sys", "") 使用全局替换语义,会删除路径中
所有 "/sys" 子串而非仅剥离前缀
2. 方案:改用 startsWith("/sys") + remove(0, 4) 仅剥离开头 4 字符
前缀,保留路径中间的 "/sys" 子串
3. 影响:仅含前缀 /sys 的路径行为不变;含多个 /sys 子串的路径不再
被错误修改;无签名变更,无性能影响
Influence:
1. 验证标准 /sys 路径的 isPathExisted 返回正确结果
2. 验证含多个 /sys 子串的路径处理正确
3. 验证无 /sys 前缀的路径行为不受影响
PMS: BUG-4
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes Flow diagram for precise sysfs prefix strippingflowchart TD
A["isPathExisted(path)"] --> B["pathT = path"]
B --> C{"pathT.startsWith(/sys)"}
C -- Yes --> D["pathT.remove(0, 4)"]
C -- No --> E["pathT unchanged"]
D --> F["hwinfo.contains(pathT)"]
E --> F
F --> G["return exists"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
lzwind
approved these changes
Oct 10, 2026
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause Analysis
DeviceInfoManager::isPathExistedusedQString::replace("/sys", "")to strip the/sysprefix from a sysfs device path before checking it against cached hwinfo data.replaceperforms global substitution, deleting every/syssubstring in the path rather than only the leading prefix. When a path contains/sysmore than once (e.g./sys/bus/sys/devices), all occurrences are removed, producing an incorrect string and a wrongcontains()result. The defect is atdeviceinfomanager.cpp:63.Fix
Replaced the global
replace("/sys", "")with astartsWith("/sys")guard followed byremove(0, 4), which strips only the leading 4-character prefix. Any/syssubstrings in the middle or end of the path are preserved.Change Safety Assessment
Code Safety
isPathExistedimplementation (commitd44d9ac9, 2021-10-30) and thereplacelogic has never been modified since — this fix does not revert any prior bug fix./systhe behavior is identical to before.Business Impact Scope
Device Manager's device enable/disable feature uses
isPathExistedto validate sysfs device paths against cached hwinfo data. After this fix, device paths containing multiple/syssubstrings are matched correctly, preventing false negatives/positives in path validation. Standard/sys/devices/...paths are unaffected.Verification Suggestion
isPathExistedreturns correct results for standard/sysprefix paths (no behavior change)./syssubstrings (e.g./sys/bus/sys/devices) are no longer over-stripped./sysprefix are unaffected.根因分析
DeviceInfoManager::isPathExisted使用QString::replace("/sys", "")在检查前剥离 sysfs 设备路径的/sys前缀。replace执行全局替换,会删除路径中所有/sys子串而非仅剥离前缀。当路径中/sys出现多次(如/sys/bus/sys/devices)时,所有出现位置均被删除,导致字符串错误、contains()判断结果错误。缺陷位于deviceinfomanager.cpp:63。修复方案
将全局
replace("/sys", "")替换为startsWith("/sys")条件判断 +remove(0, 4),仅剥离开头的 4 字符前缀,保留路径中间或末尾的/sys子串。改动安全评估
代码安全评估
isPathExisted原始实现中引入(commitd44d9ac9, 2021-10-30),replace逻辑此后从未被修改——本次修复不撤销任何历史 bug 修复。/sys的路径行为与修复前一致。业务影响范围
设备管理器的设备启用/禁用功能通过
isPathExisted校验 sysfs 设备路径。修复后,含多个/sys子串的设备路径将正确匹配,避免因路径被错误修改导致的误判。标准/sys/devices/...路径不受影响。验证建议
/sys前缀路径的isPathExisted返回正确结果(行为不变)。/sys子串的路径(如/sys/bus/sys/devices)不再被过度剥离。/sys前缀的路径行为不受影响。Summary by Sourcery
Bug Fixes:
/sysprefix and preserving any subsequent/syssegments.