From 85aa618901e013908ce077a222ed6a523414eed3 Mon Sep 17 00:00:00 2001 From: wangrong Date: Wed, 28 Oct 2026 14:34:32 +0800 Subject: [PATCH] fix: add input validation to bad sector re-verify button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- application/widgets/diskbadsectorsdialog.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/application/widgets/diskbadsectorsdialog.cpp b/application/widgets/diskbadsectorsdialog.cpp index 3503ea8..9b49444 100644 --- a/application/widgets/diskbadsectorsdialog.cpp +++ b/application/widgets/diskbadsectorsdialog.cpp @@ -1000,6 +1000,10 @@ void DiskBadSectorsDialog::onContinueButtonClicked() void DiskBadSectorsDialog::onAgainVerifyButtonClicked() { qDebug() << "Verify again button clicked"; + if (!inputValueIsEffective()) { + qWarning() << "Input values are invalid"; + return; + } m_progressBar->setValue(0); m_usedTimeLabel->setText(tr("Time elapsed:") + "00:00:00"); m_unusedTimeLabel->setText(tr("Time left:") + "00:00:00"); @@ -1021,7 +1025,19 @@ void DiskBadSectorsDialog::onAgainVerifyButtonClicked() int checkSize = m_settings->value("SettingData/CheckSize").toInt(); m_blockStart = m_settings->value("SettingData/BlockStart").toInt(); m_blockEnd = m_settings->value("SettingData/BlockEnd").toInt(); - int checkNumber = m_settings->value("SettingData/CheckNumber").toInt(); + int checkNumber = 8; + switch (m_methodComboBox->currentIndex()) { + case 0: { + checkNumber = m_checkTimesEdit->text().toInt(); + break; + } + case 1: { + checkNumber = m_timeoutEdit->text().toInt(); + break; + } + default: + break; + } QFile file("/tmp/CheckData.conf"); if (file.open(QIODevice::ReadWrite | QIODevice::Truncate)) {