fix(core/prodtest): fix error processing in prodtest_secure_channel_handshake_2
What changed, and why it matters
This commit fixes a bug in a Trezor production-test command where the device would report an error but then continue running the rest of the function anyway. Two missing 'return' statements are added so that, after an error is reported, the function exits immediately instead of falling through to later steps. In the worst case, the old code could have allowed a malformed or unauthorized secure-channel handshake to proceed further than intended, though the practical security impact is limited because this code is part of the factory production-test tooling, not normal end-user firmware operation.
Review whether the production-test tooling is reachable in released devices and confirm the prodtest binary is not shipped to end users. Audit other prodtest CLI commands for the same missing-return pattern after `cli_error()` calls. Consider adding a lint or code-review check to ensure error paths return immediately.
Security signals we found
Missing early return after error reporting
Control-flow fall-through after authentication/handshake failure
Secure channel handshake command affected
Production-test (prodtest) code path, not main wallet firmware
No changelog entry provided
Evidence from the diff
In core/embed/projects/prodtest/cmd/prodtest_secure_channel.c, the function prodtest_secure_channel_handshake_2() calls cli_error() for two error conditions (unexpected input length and failed secure_channel_handshake_2()), but previously did not return afterward. Because cli_error() does not itself terminate the caller, execution continued into the subsequent secure_channel_handshake_2(input) call or the final cli_ok(cli, "") success path. The patch adds return; after each cli_error() so the function exits on failure. This is a classic missing-early-return bug in a CLI command handler for production testing.
Changed components
core/embed/projects/prodtest/cmd/prodtest_secure_channel.cprodtest_secure_channel_handshake_2 CLI commandInspect captured patch +2 / −0
diff --git a/core/embed/projects/prodtest/cmd/prodtest_secure_channel.c b/core/embed/projects/prodtest/cmd/prodtest_secure_channel.c
index 51cc8262..183e6e3b 100644
--- a/core/embed/projects/prodtest/cmd/prodtest_secure_channel.c
+++ b/core/embed/projects/prodtest/cmd/prodtest_secure_channel.c
@@ -61,6 +61,7 @@ static void prodtest_secure_channel_handshake_2(cli_t* cli) {
cli_error(cli, PRODTEST_ERR_SECURE_CHANNEL_INPUT_LEN,
"Unexpected input length. Expecting %d bytes.",
(int)SECURE_CHANNEL_INPUT_SIZE);
+ return;
}
if (!secure_channel_handshake_2(input)) {
@@ -68,6 +69,7 @@ static void prodtest_secure_channel_handshake_2(cli_t* cli) {
// not match.
cli_error(cli, PRODTEST_ERR_SECURE_CHANNEL_HANDSHAKE_FINISH,
"`secure_channel_handshake_2()` failed.");
+ return;
}
cli_ok(cli, "");
Why this scored 44/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.