Skip to content

linux-rust: don't panic on a short Nothing firmware notification - #927

Open
cemaliplt wants to merge 1 commit into
librepods-org:linux/rustfrom
cemaliplt:cem/nothing-fw-slice
Open

cemaliplt wants to merge 1 commit into
librepods-org:linux/rustfrom
cemaliplt:cem/nothing-fw-slice

Conversation

@cemaliplt

Copy link
Copy Markdown

What was wrong

linux-rust/src/devices/nothing.rs (firmware-version notification handler) checked data.starts_with(&[0x55,0x20,0x01,0x42,0x40]), which only guarantees 5 bytes, then read data[8..]. A 5–7 byte notification with that prefix panics, and Cargo.toml sets panic = "abort" for release builds, so the whole app exits.

Fix

A small pure function parse_firmware_version(&[u8]) -> Option<String> returns None when the prefix does not match or the packet is shorter than 8 bytes. The call site uses if let Some(..). Output for valid packets is unchanged.

Verified

cd linux-rust && cargo test --release --locked: test result: ok. 3 passed; 0 failed (prefix-only 5 bytes → None, valid packet with "1.2.3" → Some, non-matching packet → None).

Not verified

Not tested with a real Nothing device. #892 and #888 also edit nothing.rs (other parts of the file) and may need a trivial rebase.

🤖 Generated with Claude Code

The firmware-version notification handler matched only the 5-byte prefix with starts_with and then sliced data[8..], so a 5-7 byte notification panicked. Release builds use panic = "abort", so the whole app died.

Extract parse_firmware_version(data) -> Option<String>. It returns None when the prefix does not match or the packet is shorter than 8 bytes. The call site uses it with if let, so the else-if chain behaves as before. Valid packets keep the same output.

Verified: cargo test --release --locked (CARGO_TARGET_DIR shared) passes, including three new tests: prefix-only 5-byte packet returns None, a valid packet yields "1.2.3", and a non-matching packet returns None.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant