Fix: WiFi Interface Frame Parsing #1308
Merged
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.
This PR implements frame header parsing for the TCP/WiFI interface used in the companion firmware.
Currently, it's possible for the WiFi firmware to crash if you send TCP packets faster than the firmware can process them.
This happens due to
client.available()having more bytes available than theMAX_FRAME_SIZEallows for.The current implementation tries to copy all of the available bytes into the buffer, resulting in overflow/stack smashing.
I've added parsing of the protocol provided frame header, which tells us how many bytes we should expect to follow.
If we haven't received enough bytes yet, which could happen on slow links, it will wait for the next loop and check again.
I've been working on fast channel syncing in the mobile app, which works on BLE connections, however noticed the WiFi firmware would crash due to the large amount of bytes available.
In addition to this, I've also added new checks to ensure frames that are of unexpected type, or are larger than the
MAX_FRAME_SIZEare skipped.Requesting review from @fdlamotte as you were the original author ;)