Repository navigation
fix: add input validation to bad sector re-verify button - #236
wangrong1069 wants to merge 1 commit into
Conversation
1. Root cause: onAgainVerifyButtonClicked() lacked inputValueIsEffective() guard, allowing out-of-range timeout values (e.g. 1, valid: 100-3000) to proceed with re-verification; it also read checkNumber from stale QSettings cache instead of current UI fields 2. Fix: add inputValueIsEffective() guard at function entry (matching onStartVerifyButtonClicked), and read checkNumber from UI fields via m_methodComboBox switch instead of QSettings cache 3. Impact: re-verify button now validates input same as start-verify; no signature change, existing unit test (timeout=300) still passes Log: 坏道重新检测按钮增加输入校验,拦截超范围超时时间 Influence: 1. Test re-verify with valid timeout value (e.g. 300) proceeds normally 2. Test re-verify with out-of-range timeout (e.g. 1) is blocked 3. Test re-verify with out-of-range check times (e.g. 0 or 17) is blocked fix: 坏道重新检测按钮增加输入校验 1. 根因:onAgainVerifyButtonClicked() 缺少 inputValueIsEffective() 校验守卫, 超范围超时时间(如 1,有效范围 100-3000)可通过重新检测;同时从 QSettings 缓存读取 checkNumber 而非当前 UI 字段 2. 方案:在函数入口添加 inputValueIsEffective() 守卫(与 onStartVerifyButtonClicked 对齐),并通过 m_methodComboBox 开关 从 UI 字段读取 checkNumber,不再使用 QSettings 缓存 3. 影响:重新检测按钮与首次检测按钮校验行为一致;无签名变更, 既有单元测试(超时=300)不受影响 Log: 坏道重新检测按钮增加输入校验,拦截超范围超时时间 Influence: 1. 测试重新检测时输入有效超时值(如 300)正常执行 2. 测试重新检测时输入超范围超时值(如 1)被拦截 3. 测试重新检测时输入超范围检测次数(如 0 或 17)被拦截 PMS: BUG-350579
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: wangrong1069 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 GuideThe re-verify action now applies the same input validation as initial verification and derives its check count from the current UI selection, preventing invalid or stale parameters from being used. Sequence diagram for validated bad-sector re-verificationsequenceDiagram
actor User
participant Dialog as DiskBadSectorsDialog
participant Input as Current UI inputs
participant Verify as Verification process
User->>Dialog: onAgainVerifyButtonClicked()
Dialog->>Dialog: inputValueIsEffective()
alt invalid input
Dialog-->>User: return
else valid input
Dialog->>Input: currentIndex()
Dialog->>Input: text().toInt()
Dialog->>Verify: start re-verification with current checkNumber
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无语法逻辑问题,代码保持良好。'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['无代码质量问题,代码保持良好。'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['建议将默认值8定义为命名常量,如 static const int kDefaultCheckNumber = 8;,提高代码可维护性。'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['无安全问题,输入验证的添加是一个积极的安全改进。'] 💡 改进建议代码示例// 建议将魔法数字8定义为命名常量 // 在类定义或文件头部添加: static const int kDefaultCheckNumber = 8;
// 在 onAgainVerifyButtonClicked() 中使用: int checkNumber = kDefaultCheckNumber; switch (m_methodComboBox->currentIndex()) { case 0: {
checkNumber = m_checkTimesEdit->text().toInt();
break;
} case 1: {
checkNumber = m_timeoutEdit->text().toInt();
break;
} default:
break;
}本报告由 AI 代码审查工具自动生成 |
|
TAG Bot New tag: 6.0.28 |
|
TAG Bot New tag: 6.0.29 |
|
TAG Bot New tag: 6.0.30 |
Root Cause Analysis
The "re-verify" button (
onAgainVerifyButtonClicked()) in the bad sector verification dialog lacked theinputValueIsEffective()validation guard thatonStartVerifyButtonClicked()already had. This allowed out-of-range timeout values (e.g. 1, when valid range is 100-3000) to proceed with re-verification. Additionally,checkNumberwas read from stale QSettings cache (m_settings->value("SettingData/CheckNumber")) instead of the current UI input fields, causing re-verification to use outdated values.Key evidence:
diskbadsectorsdialog.cpp:640(onStartVerifyButtonClickedhas guard) vsdiskbadsectorsdialog.cpp:1000(onAgainVerifyButtonClickedlacked guard);inputValueIsEffective()at line 531 validates timeout range 100-3000.修复方案
Added
inputValueIsEffective()guard at the top ofonAgainVerifyButtonClicked()(after the debug log, before any state changes), and replaced the QSettings cache read forcheckNumberwith aswitch(m_methodComboBox->currentIndex())that reads fromm_checkTimesEditorm_timeoutEdit— matching the existing pattern inonStartVerifyButtonClicked()exactly.Change Safety Assessment
Code Safety
onAgainVerifyButtonClicked()was introduced in commit34ed42a(2020-12-29) and never had input validation; this change does not revert any historical fixdiskbadsectorsdialog.h:123, unchanged) and a unit test (ut_application.cpp:681, which sets timeout=300 within valid range, so the guard passes and behavior is unchanged)Business Impact Scope
Affected module: Bad sector verification dialog in disk manager. The fix ensures the "re-verify" button validates user input (check times 1-16, timeout 100-3000) before proceeding, consistent with the "start verify" button. Users who enter out-of-range values and click "re-verify" will now be blocked instead of proceeding with invalid parameters.
Verification Suggestion
Regression test: verify that re-verify with valid timeout (e.g. 300) proceeds normally, and re-verify with out-of-range timeout (e.g. 1) is blocked. Also verify re-verify with out-of-range check times (e.g. 0 or 17) is blocked.
根因分析
坏道检测对话框中的"重新检测"按钮(
onAgainVerifyButtonClicked())缺少inputValueIsEffective()校验守卫,而"开始检测"按钮(onStartVerifyButtonClicked())已有该校验。这导致超范围超时时间(如 1,有效范围为 100-3000)可通过重新检测。此外,checkNumber从 QSettings 缓存读取而非当前 UI 输入字段,导致重新检测使用过期值。关键证据:
diskbadsectorsdialog.cpp:640(onStartVerifyButtonClicked有守卫)对比diskbadsectorsdialog.cpp:1000(onAgainVerifyButtonClicked缺少守卫);inputValueIsEffective()在第 531 行校验超时范围 100-3000。修复方案
在
onAgainVerifyButtonClicked()函数顶部添加inputValueIsEffective()守卫(在调试日志之后、任何状态变更之前),并将checkNumber的 QSettings 缓存读取替换为switch(m_methodComboBox->currentIndex())从m_checkTimesEdit或m_timeoutEdit读取,与onStartVerifyButtonClicked()的既有模式完全一致。改动安全评估
代码安全评估
onAgainVerifyButtonClicked()在 commit34ed42a(2020-12-29)引入以来从未有输入校验,本次改动不撤销任何历史修复diskbadsectorsdialog.h:123,未修改)和单元测试(ut_application.cpp:681,测试设置 timeout=300 在有效范围内,守卫通过,行为不变)业务影响范围
受影响模块:磁盘管理器坏道检测对话框。修复确保"重新检测"按钮在执行前校验用户输入(检测次数 1-16,超时时间 100-3000),与"开始检测"按钮行为一致。用户输入超范围值后点击"重新检测"将被拦截。
验证建议
回归测试:验证重新检测时输入有效超时值(如 300)正常执行,输入超范围超时值(如 1)被拦截,输入超范围检测次数(如 0 或 17)被拦截。
PMS: BUG-350579
Summary by Sourcery
Validate re-verification inputs and apply the current dialog values when restarting bad-sector verification.
Bug Fixes: