Skip to content

Commit 4bbf5dd

Browse files
committed
Detailed error message for passphrases with null chars
Since users may have thought the null characters in their passphrases were actually evaluated prior to this change, they may be surprised to learn that their passphrases no longer work. Give them feedback to explain how to remedy the issue.
1 parent b4bdabc commit 4bbf5dd

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

src/qt/askpassphrasedialog.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,19 @@ void AskPassphraseDialog::accept()
153153
case Unlock:
154154
try {
155155
if (!model->setWalletLocked(false, oldpass)) {
156-
QMessageBox::critical(this, tr("Wallet unlock failed"),
157-
tr("The passphrase entered for the wallet decryption was incorrect."));
156+
// Check if the passphrase has a null character (see #27067 for details)
157+
if (oldpass.find('\0') == std::string::npos) {
158+
QMessageBox::critical(this, tr("Wallet unlock failed"),
159+
tr("The passphrase entered for the wallet decryption was incorrect."));
160+
} else {
161+
QMessageBox::critical(this, tr("Wallet unlock failed"),
162+
tr("The passphrase entered for the wallet decryption is incorrect. "
163+
"It contains a null character (ie - a zero byte). "
164+
"If the passphrase was set with a version of this software prior to 25.0, "
165+
"please try again with only the characters up to — but not including — "
166+
"the first null character. If this is successful, please set a new "
167+
"passphrase to avoid this issue in the future."));
168+
}
158169
} else {
159170
QDialog::accept(); // Success
160171
}
@@ -173,8 +184,18 @@ void AskPassphraseDialog::accept()
173184
}
174185
else
175186
{
176-
QMessageBox::critical(this, tr("Wallet encryption failed"),
177-
tr("The passphrase entered for the wallet decryption was incorrect."));
187+
// Check if the old passphrase had a null character (see #27067 for details)
188+
if (oldpass.find('\0') == std::string::npos) {
189+
QMessageBox::critical(this, tr("Passphrase change failed"),
190+
tr("The passphrase entered for the wallet decryption was incorrect."));
191+
} else {
192+
QMessageBox::critical(this, tr("Passphrase change failed"),
193+
tr("The old passphrase entered for the wallet decryption is incorrect. "
194+
"It contains a null character (ie - a zero byte). "
195+
"If the passphrase was set with a version of this software prior to 25.0, "
196+
"please try again with only the characters up to — but not including — "
197+
"the first null character."));
198+
}
178199
}
179200
}
180201
else

src/wallet/rpc/encrypt.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,17 @@ RPCHelpMan walletpassphrase()
6868
}
6969

7070
if (!pwallet->Unlock(strWalletPass)) {
71-
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
71+
// Check if the passphrase has a null character (see #27067 for details)
72+
if (strWalletPass.find('\0') == std::string::npos) {
73+
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
74+
} else {
75+
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered is incorrect. "
76+
"It contains a null character (ie - a zero byte). "
77+
"If the passphrase was set with a version of this software prior to 25.0, "
78+
"please try again with only the characters up to — but not including — "
79+
"the first null character. If this is successful, please set a new "
80+
"passphrase to avoid this issue in the future.");
81+
}
7282
}
7383

7484
pwallet->TopUpKeyPool();
@@ -143,7 +153,16 @@ RPCHelpMan walletpassphrasechange()
143153
}
144154

145155
if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) {
146-
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
156+
// Check if the old passphrase had a null character (see #27067 for details)
157+
if (strOldWalletPass.find('\0') == std::string::npos) {
158+
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
159+
} else {
160+
throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The old wallet passphrase entered is incorrect. "
161+
"It contains a null character (ie - a zero byte). "
162+
"If the old passphrase was set with a version of this software prior to 25.0, "
163+
"please try again with only the characters up to — but not including — "
164+
"the first null character.");
165+
}
147166
}
148167

149168
return UniValue::VNULL;

0 commit comments

Comments
 (0)