Repository navigation
fix: resolve dangling pointer in filePath - #411
deepin-bot[bot] merged 1 commit into
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes incorrect directory traversal counts caused by filePath() returning pointers to destroyed temporary QByteArrays. The private helper now returns an owning QByteArray, and its callers explicitly preserve or consume that storage safely before using the underlying path data. Sequence diagram for safe filePath lifetime during directory sortingsequenceDiagram
participant D as DEnumeratorPrivate
participant B as QByteArray
participant F as fts
D->>D: filePath(uri)
D->>B: Return owning path bytes
D->>B: constData()
B-->>D: Stable path pointer
D->>F: fts_read()
D->>D: sortFileInfoList()
D->>B: Destroy after path use
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
d34e8c9 to
a060a74
Compare
1. Root cause: DEnumeratorPrivate::filePath() returned toUtf8().data()/toLatin1().data() from temporary QByteArray, causing dangling pointer after function return 2. Fix: change filePath() to return QByteArray by value, ensuring RAII lifetime; openDirByfts() wraps result with strdup() for fts_open, sortFileInfoList() uses constData() directly 3. Impact: eliminates dangling pointer and manual free() in sortFileInfoList(), fixing incorrect file counts in directory traversal; remove unused stdio.h include in dfm-list Log: Fix incorrect directory traversal file counts caused by dangling pointer in filePath Influence: 1. Test directory enumeration returns correct file counts 2. Test directory traversal with special characters in paths 3. Verify no memory leaks in filePath and sortFileInfoList fix: 修复 filePath 悬垂指针导致目录遍历文件计数错误 1. 根因:DEnumeratorPrivate::filePath() 通过 toUtf8().data()/ toLatin1().data() 返回临时 QByteArray 的内部指针,函数返回 后临时对象销毁产生悬垂指针 2. 方案:将 filePath() 返回类型改为 QByteArray(按值返回),利用 RAII 管理生命周期;openDirByfts() 用 strdup() 包装供 fts_open 使用,sortFileInfoList() 直接使用 constData() 3. 影响:消除 sortFileInfoList() 中的悬垂指针和手动 free(), 修复目录遍历文件计数不正确的问题 Log: 修复目录遍历文件计数不正确的问题 Influence: 1. 测试目录遍历返回正确的文件数量 2. 测试包含特殊字符路径的目录遍历 3. 验证 filePath 和 sortFileInfoList 无内存泄漏 PMS: BUG-380499 BUG-333909
a060a74 to
ad0c939
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: liyigang1, max-lvs 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 |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
745c132
into
linuxdeepin:release/eagle
修复 PMS BUG-380499:目录遍历文件计数不正确
根因
DEnumeratorPrivate::filePath()通过return path.toUtf8().data()/url.userInfo()...toLatin1().data()返回char*,临时QByteArray在函数返回时被销毁,导致悬垂指针。sortFileInfoList()中使用该悬垂指针做strcmp触发未定义行为,导致目录遍历返回错误的文件数量。修复方案
使用
strdup()分配堆内存返回路径字符串,由调用方负责free()释放。返回类型保持char*不变,两处调用点(openDirByfts()和sortFileInfoList())均增加空指针检查并正确释放内存。同时移除dfm-list.cpp中未使用的#include <stdio.h>。改动文件
src/dfm-io/dfm-io/denumerator.cpp:filePath()使用strdup()分配堆内存;openDirByfts()和sortFileInfoList()增加空指针检查与内存释放src/dfm-io/tools/dfm-list.cpp:移除未使用的#include <stdio.h>影响范围
filePath()为 private 方法,返回类型char*未变,无 API/ABI 影响。Summary by Sourcery
Fix directory enumeration to use valid file path data and report allocation failures safely.
Bug Fixes:
Enhancements: