fix(crowtty): don't panic on 1-byte SerMux frames #117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently,
crowtty
callscarry[..used].split_at(2)
every time it decodes a COBS-encoded frame SerMux frame, to extract the port component from the frame. However, if we send a zero byte while not currently in a frame, the COBS decoder will interpret it as a frame with a single zero in it. When we callsplit_at
, crowtty will panic, because the slice only has one byte in it.Commit 5231001 changed the panic handler to always send a zero before writing out the panic message, in order to terminate the current SerMux frame if one is in the process of being sent. However, that zero makes crowtty crash if it is not decoding a partial frame. This means that, rather than nicely printing the panic message, crowtty just panics immediately when the board panics. That kinda sucks.
This branch fixes this, by changing crowtty to check whether the length of the decoded COBS frame is less than the minimum frame length (the 2-byte port number). Now, if we decode a single-byte zero frame, we'll just ignore it and keep going.