fix(core/prodtest): handle return values in NFC test
What changed, and why it matters
This commit fixes a small coding issue in Trezor's factory production-test tool for NFC hardware. Previously, two NFC setup functions were called without checking whether they succeeded. Now the code checks their return values and reports a fatal error if they fail, then jumps to cleanup. This is a defensive quality improvement in a diagnostic/testing utility, not a fix for an exploitable security vulnerability in the wallet firmware itself.
No urgent action needed. Treat as a normal code-quality/defensive fix. If auditing the prodtest tool, verify that other NFC and peripheral setup calls also check return values and that cleanup paths release any acquired resources.
Security signals we found
Unchecked return values corrected
Error-handling path added to NFC initialization
Change is confined to production-test firmware, not main wallet firmware
Evidence from the diff
In core/embed/projects/prodtest/cmd/prodtest_nfc.c, the prodtest_nfc_read_card() function previously ignored return codes from nfc_register_tech() and nfc_activate_stm(). The patch wraps both calls in NFC_OK checks, emits CLI_ERROR_FATAL messages, and branches to cleanup on failure. This prevents the function from continuing NFC polling after a failed initialization. The change is in the prodtest (production test) project, not the main firmware runtime, and only affects the NFC manufacturing-test command.
Changed components
core/embed/projects/prodtest/cmd/prodtest_nfc.cTrezor production-test NFC commandInspect captured patch +10 / −3
diff --git a/core/embed/projects/prodtest/cmd/prodtest_nfc.c b/core/embed/projects/prodtest/cmd/prodtest_nfc.c
index cbc2064a..e289ebdb 100644
--- a/core/embed/projects/prodtest/cmd/prodtest_nfc.c
+++ b/core/embed/projects/prodtest/cmd/prodtest_nfc.c
@@ -58,9 +58,16 @@ static void prodtest_nfc_read_card(cli_t* cli) {
}
}
- nfc_register_tech(NFC_POLLER_TECH_A | NFC_POLLER_TECH_B | NFC_POLLER_TECH_F |
- NFC_POLLER_TECH_V);
- nfc_activate_stm();
+ if (NFC_OK != nfc_register_tech(NFC_POLLER_TECH_A | NFC_POLLER_TECH_B |
+ NFC_POLLER_TECH_F | NFC_POLLER_TECH_V)) {
+ cli_error(cli, CLI_ERROR_FATAL, "NFC tech registration failed");
+ goto cleanup;
+ }
+
+ if (NFC_OK != nfc_activate_stm()) {
+ cli_error(cli, CLI_ERROR_FATAL, "NFC activation failed");
+ goto cleanup;
+ }
nfc_event_t nfc_event;
uint32_t expire_time = ticks_timeout(timeout);
Why this scored 19/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.