Fix client process for large packets#221
Open
mriksman wants to merge 2 commits intomaximkulkin:masterfrom
Open
Fix client process for large packets#221mriksman wants to merge 2 commits intomaximkulkin:masterfrom
mriksman wants to merge 2 commits intomaximkulkin:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue 1
When a large packet is received (greater than 1042), it is broken into separate parts. The calculation for
decrypted_sizehad the incorrect value of18instead of16, sodecrypted sizewas being calculated as1022. Whenclient_decryptwas called,decrypted_sizeof1022was less than the calculatedrequired_decrypted_sizeof1024causing it to fail withr = -2.The error logs showed:
It then read the remaining part of the data, but was unable to decrypt it (perhaps because the first part wasn't decrypted?)
Adjusting the number from
18to16resolved the issue.Issue 2
I noticed that
homekit_client_processwas exiting before the full message was completed.The JSON is incomplete, and the HTTP parser has not indicated that the response was completed. Under low loads, the function would execute again, read the remaining part of the JSON, and successfully finish the message. However, under heavy client loads, it was possible for another client to connect and be processed, with the function trying to merge Client 1 and Client 4 data.
It appears that in the
whilecheck,data_availableis always0as the buffer equals the block size. I believe this loop should only exit once the HTTP parser has indicated the message is indeed complete.The logs now look correct.