fix(core/bootloader_emu): write the storage marker after parsing the options [no changelog]
What changed, and why it matters
This change fixes a minor bug in the Trezor bootloader emulator, a software simulation tool used for development and testing. Previously, simply running the emulator with a help flag (-h) would write a marker to a simulated flash file, even though the user only wanted information. Now the marker is written only after command-line options are parsed, so informational invocations no longer touch the flash file. This is a correctness fix for a development tool, not a fix for a vulnerability in real Trezor hardware wallets.
No urgent action needed. This is a low-risk correctness fix for an emulator used in development and testing. Users building or testing the bootloader emulator can update to include this commit to avoid spurious flash-file modifications when running help commands.
Security signals we found
Unintended persistent state modification by a development/testing tool
Side effect in help/informational code path
Evidence from the diff
In core/embed/projects/bootloader/emulator.c, the code that writes a dummy 0x12345678 marker into STORAGE_AREAS[0] to simulate non-empty storage was moved from before getopt parsing to after it. The original placement caused any invocation of the emulator binary, including -h/–help, to modify the backing flash file. The patch prevents unintended side effects during informational/help-only runs. The marker write result is explicitly discarded with (void)ret, which remains unchanged.
Changed components
core/embed/projects/bootloader/emulator.cTrezor bootloader emulator (development/testing tool only)Inspect captured patch +9 / −8
### core/embed/projects/bootloader/emulator.c
@@ -146,14 +146,6 @@ int main(int argc, char **argv) {
FIRMWARE_START = (uintptr_t)flash_area_get_address(&FIRMWARE_AREA, 0, 0);
- // simulate non-empty storage so that we know whether it was erased or not
- if (storage_empty(&STORAGE_AREAS[0])) {
- uint32_t data = 0x12345678;
- secbool ret =
- flash_area_write_data(&STORAGE_AREAS[0], 0, &data, sizeof(data));
- (void)ret;
- }
-
int opt;
bool display_error = false;
uint8_t set_variant = 0xff;
@@ -207,6 +199,15 @@ int main(int argc, char **argv) {
}
}
+ // simulate non-empty storage so that we know whether it was erased or
+ // not (after option parsing, so that e.g. -h does not touch the flash file)
+ if (storage_empty(&STORAGE_AREAS[0])) {
+ uint32_t data = 0x12345678;
+ secbool ret =
+ flash_area_write_data(&STORAGE_AREAS[0], 0, &data, sizeof(data));
+ (void)ret;
+ }
+
if (display_error) {
const char *message, *title = NULL, *footer = NULL;
if (optind < argc) {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.