|
21 | 21 | #include <QSet> |
22 | 22 | #include <QMessageBox> |
23 | 23 |
|
| 24 | +#include <algorithm> |
| 25 | + |
24 | 26 | MnemonicVerificationDialog::MnemonicVerificationDialog(const SecureString& mnemonic, QWidget *parent) : |
25 | 27 | QDialog(parent, GUIUtil::dialog_flags), |
26 | 28 | ui(new Ui::MnemonicVerificationDialog), |
@@ -141,7 +143,25 @@ void MnemonicVerificationDialog::setupStep2() |
141 | 143 | ui->stackedWidget->setCurrentIndex(1); |
142 | 144 | // Parse words for validation (needed in step 2) |
143 | 145 | parseWords(); |
| 146 | + |
| 147 | + // Validate mnemonic has at least 3 words before proceeding |
| 148 | + const int wordCount = getWordCount(); |
| 149 | + if (wordCount < 3) { |
| 150 | + QMessageBox::critical(this, tr("Invalid Mnemonic"), |
| 151 | + tr("Mnemonic phrase has fewer than 3 words (found %1). Verification cannot proceed.").arg(wordCount)); |
| 152 | + reject(); |
| 153 | + return; |
| 154 | + } |
| 155 | + |
144 | 156 | generateRandomPositions(); |
| 157 | + |
| 158 | + // Safety check: ensure positions were generated successfully |
| 159 | + if (m_selected_positions.size() < 3) { |
| 160 | + QMessageBox::critical(this, tr("Verification Error"), |
| 161 | + tr("Failed to generate verification positions. Please try again.")); |
| 162 | + reject(); |
| 163 | + return; |
| 164 | + } |
145 | 165 |
|
146 | 166 | ui->word1Edit->clear(); |
147 | 167 | ui->word2Edit->clear(); |
@@ -214,7 +234,11 @@ void MnemonicVerificationDialog::setupStep2() |
214 | 234 | void MnemonicVerificationDialog::generateRandomPositions() |
215 | 235 | { |
216 | 236 | m_selected_positions.clear(); |
217 | | - const int n = std::max(1, getWordCount()); |
| 237 | + const int n = getWordCount(); |
| 238 | + if (n < 3) { |
| 239 | + // Unable to verify; bail out so the dialog can surface an error message upstream. |
| 240 | + return; |
| 241 | + } |
218 | 242 | QSet<int> used; |
219 | 243 | QRandomGenerator* rng = QRandomGenerator::global(); |
220 | 244 | while (m_selected_positions.size() < 3) { |
|
0 commit comments