Repository navigation
Conversation
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes driver-control configuration loss and unusable boot-on-load behavior by safely opening and rewriting files, correcting /etc and /usr configuration paths, handling the intended lib directory, and validating non-existent target paths without weakening traversal protection. Sequence diagram for safe driver configuration file rewritingsequenceDiagram
participant ModCore
participant QFile
participant QTextStream
ModCore->>QFile: open(QIODevice::ReadWrite | QIODevice::Text)
alt file opened
ModCore->>QFile: seek(0)
ModCore->>QTextStream: read configuration content
ModCore->>QFile: resize(0)
ModCore->>QFile: seek(0)
ModCore->>QTextStream: write updated content
ModCore->>QTextStream: flush()
ModCore->>QFile: close()
else open failed
ModCore-->>ModCore: return
end
Flow diagram for secure driver configuration path validationflowchart TD
A[Build target path] --> B[canonicalFilePath]
B --> C{Canonical path exists?}
C -->|Yes| D[Validate path within base directory]
C -->|No| E[cleanPath absoluteFilePath]
E --> D
D --> F{Within base directory?}
F -->|Yes| G[Allow configuration operation]
F -->|No| H[Reject path]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 边界处理完善 ✅ 通过 潜在问题: 建议: ['将 tmpfile.seek(0) 改为 stream.seek(0),确保 QTextStream 内部缓冲与底层设备位置同步'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['文件打开失败时增加 qCWarning 日志输出,如 qCWarning(appLog) << "Failed to open file:" << filepath', '删除 setModLoadedOnBoot 中不再使用的 QFileInfo fileinfo(LOADONBOOT_PROBE_DIR) 语句'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// modcore.cpp - deleteLineOfFileWithItem 修复建议
void ModCore::deleteLineOfFileWithItem(const QString &filepath, const QString &item)
{
QFile tmpfile(filepath);
if (!tmpfile.open(QIODevice::ReadWrite | QIODevice::Text)) {
qCWarning(appLog) << "Failed to open file for editing:" << filepath;
return;
}
//设置文件游标到起始位置
tmpfile.seek(0);
QTextStream stream(&tmpfile);
// ... 读取与过滤逻辑 ...
//清除原有内容
tmpfile.resize(0);
stream.seek(0); // 使用 stream.seek(0) 同步 QTextStream 内部状态
stream << newcontent;
stream.flush();
tmpfile.close();
}
// modcore.cpp - setModLoadedOnBoot 修复建议:删除未使用变量
bool ModCore::setModLoadedOnBoot(const QString &modName)
{
// 已删除: QFileInfo fileinfo(LOADONBOOT_PROBE_DIR); // 不再使用
QString strfilename = QString(LOADONBOOT_FILENAME_TEMPLETE).arg(modName);
QString filepath = QDir(LOADONBOOT_PROBE_DIR).absoluteFilePath(strfilename);
// 路径边界检查:确保最终路径在预期目录内
if (!isPathWithinDirectory(filepath, LOADONBOOT_PROBE_DIR)) {
return false;
}
// ...
}本报告由 AI 代码审查工具自动生成 |
1. Root cause: deleteLineOfFileWithItem never called QFile::open() before seek/read/write, but resize(0) still truncated the real file, wiping entire config files (data loss) 2. Fix: add open(QIODevice::ReadWrite | QIODevice::Text) guard before file operations; add seek(0) after resize(0) to reset cursor to start (resize does not move the file cursor); add stream.flush() before close() to ensure data is written to disk 3. Root cause: setModLoadedOnBoot used QFileInfo(dir).dir() which returns the parent directory, producing out-of-bounds paths that always fail the path guard, making boot-on-load feature unusable 4. Fix: use QDir(LOADONBOOT_PROBE_DIR).absoluteFilePath() for correct path construction 5. Root cause: rmFromBlackList libdir loop copy-pasted etcdir, so /usr/lib/modprobe.d files were never processed 6. Fix: change etcdir to libdir in the libdir traversal loop 7. Root cause: isPathWithinDirectory used canonicalFilePath() which returns empty for non-existent files, rejecting legitimate new config file paths created by addModBlackList/setModLoadedOnBoot 8. Fix: fall back to QDir::cleanPath(absoluteFilePath) when canonical path is empty, preserving path traversal protection Log: fix driver control config file data loss and boot-on-load failure Influence: 1. Test blacklist removal preserves non-matching lines in config files 2. Test setModLoadedOnBoot creates config in /etc/modules-load.d correctly 3. Test rmFromBlackList processes /usr/lib/modprobe.d directory files 4. Test addModBlackList accepts legitimate new file paths 5. Verify no path traversal regression in isPathWithinDirectory fix: 修复驱动管理模块配置文件数据丢失及路径错误 1. 根因:deleteLineOfFileWithItem 未调用 QFile::open() 即执行 seek/read/write,但 resize(0) 仍截断实际文件,导致整个配置 文件被清空(数据丢失) 2. 方案:在文件操作前增加 open(QIODevice::ReadWrite | QIODevice::Text) 保护;在 resize(0) 后增加 seek(0) 将游标重置到起始位置(resize 不移动文件游标);在 close() 前增加 stream.flush() 确保数据落盘 3. 根因:setModLoadedOnBoot 使用 QFileInfo(dir).dir() 返回父目录, 拼出越界路径导致边界检查恒失败,开机自启动功能不可用 4. 方案:改用 QDir(LOADONBOOT_PROBE_DIR).absoluteFilePath() 正确 构建路径 5. 根因:rmFromBlackList 的 libdir 循环复制粘贴误用 etcdir, /usr/lib/modprobe.d 下文件从未被处理 6. 方案:将 libdir 循环中的 etcdir 改为 libdir 7. 根因:isPathWithinDirectory 使用 canonicalFilePath() 对不存在 文件返回空串,拒绝 addModBlackList/setModLoadedOnBoot 创建的 合法新文件路径 8. 方案:canonical 路径为空时回退 QDir::cleanPath(absoluteFilePath), 保留路径穿越防护 Log: 修复驱动管理配置文件数据丢失及开机自启动失效 Influence: 1. 测试黑名单移除后配置文件正确保留非匹配行 2. 测试 setModLoadedOnBoot 正确在 /etc/modules-load.d 创建配置 3. 测试 rmFromBlackList 正确处理 /usr/lib/modprobe.d 目录文件 4. 测试 addModBlackList 接受合法新文件路径 5. 验证 isPathWithinDirectory 无路径穿越回归
a8e28eb to
f1a47b8
Compare
|
TAG Bot New tag: 6.0.75 |
fix: fix data loss and path bugs in drivercontrol module
before seek/read/write, but resize(0) still truncated the real
file, wiping entire config files (data loss)
file operations; add seek(0) after resize(0) to reset cursor to
start (resize does not move the file cursor); add stream.flush()
before close() to ensure data is written to disk
returns the parent directory, producing out-of-bounds paths that
always fail the path guard, making boot-on-load feature unusable
path construction
/usr/lib/modprobe.d files were never processed
returns empty for non-existent files, rejecting legitimate new
config file paths created by addModBlackList/setModLoadedOnBoot
path is empty, preserving path traversal protection
Log: fix driver control config file data loss and boot-on-load failure
Influence:
fix: 修复驱动管理模块配置文件数据丢失及路径错误
seek/read/write,但 resize(0) 仍截断实际文件,导致整个配置
文件被清空(数据丢失)
保护;在 resize(0) 后增加 seek(0) 将游标重置到起始位置(resize
不移动文件游标);在 close() 前增加 stream.flush() 确保数据落盘
拼出越界路径导致边界检查恒失败,开机自启动功能不可用
构建路径
/usr/lib/modprobe.d 下文件从未被处理
文件返回空串,拒绝 addModBlackList/setModLoadedOnBoot 创建的
合法新文件路径
保留路径穿越防护
Log: 修复驱动管理配置文件数据丢失及开机自启动失效
Influence:
Summary by Sourcery
Fix driver control configuration updates and path validation to prevent data loss and restore blacklist and boot-on-load functionality.
Bug Fixes: