-
Notifications
You must be signed in to change notification settings - Fork 121
bug: Prevent memory_reset_hww from masking flash write failures #1707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: Prevent memory_reset_hww from masking flash write failures #1707
Conversation
benma
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
src/memory/memory.c
Outdated
| rust_noise_generate_static_private_key(rust_util_bytes_mut( | ||
| chunk.fields.noise_static_private_key, sizeof(chunk.fields.noise_static_private_key))); | ||
| bool res = _write_chunk(CHUNK_1, chunk.bytes); | ||
| if (!_write_chunk(CHUNK_1, chunk.bytes)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the original intention was to run the below BLE stuff even if this fails, so to preserve this, just assign bool res1 and bool res2 and return res1 && res2?
55104dd to
16b777b
Compare
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/memory/memory.c
Outdated
| chunk_shared.fields.ble_identity_address[0] |= 0xc; | ||
|
|
||
| memset(&chunk_shared.fields.ble_bond_db, 0xff, sizeof(chunk_shared.fields.ble_bond_db)); | ||
| res |= _write_to_address(FLASH_SHARED_DATA_START, 0, chunk_shared.bytes); | ||
| res = res && _write_to_address(FLASH_SHARED_DATA_START, 0, chunk_shared.bytes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure shared flash reset executes even after chunk write failure
Using res = res && _write_to_address(...) short-circuits the shared BLE reset when _write_chunk(CHUNK_1, ...) fails because res is already false. The commit message says both writes should still be attempted, but this change prevents the second write from running and leaves shared BLE data unchanged on partial failures. Consider invoking the shared write unconditionally and combining results afterward so both operations are attempted while still returning false if either fails.
Useful? React with 👍 / 👎.
memory_reset_hww combined the CHUNK_1 write result and the shared BLE chunk write using |=, so a later successful write could hide an earlier failure. Change both writes to be checked individually and return false on the first failure, making the function only report success when all flash writes succeed.
16b777b to
42b1a4c
Compare
|
|
||
| memset(&chunk_shared.fields.ble_bond_db, 0xff, sizeof(chunk_shared.fields.ble_bond_db)); | ||
| res |= _write_to_address(FLASH_SHARED_DATA_START, 0, chunk_shared.bytes); | ||
| res = _write_to_address(FLASH_SHARED_DATA_START, 0, chunk_shared.bytes) && res; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
relevant: https://c0x.shape-of-code.com/6.5.13.html
first operand always executes
benma
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
memory_reset_hww combined the CHUNK_1 write result and the shared BLE chunk write using |=, so a later successful write could hide an earlier failure. Change both writes to be checked individually and return false if any of the two write operations fails, but ensuring both operations are attempted.
What could go wrong in the old code:
when
_write_chunk(CHUNK_1, chunk.bytes);returnfalseand_write_to_address(FLASH_SHARED_DATA_START, 0, chunk_shared.bytes)returns true, thenbool memory_reset_hww(void)returns true due to the|=operator.