Skip to content

Commit

Permalink
Fix off-by-one error when truncating buffer
Browse files Browse the repository at this point in the history
The __receive_buffer is always truncated by
[chars_processed_successfully + 1:].  When a partial socketcand frame is
received, chars_processed_successfully is 0, and this results in 1
character being discarded. This will be the '<' character, and thus when
the rest of the frame is received, it will be treated as a bad frame,
and discarded.
  • Loading branch information
faisal-shah committed Nov 30, 2023
1 parent 2e58a21 commit 9a8dbd6
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions can/interfaces/socketcand/socketcand.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ def _recv_internal(self, timeout):
self.__message_buffer.append(parsed_can_message)
buffer_view = buffer_view[end + 1 :]

self.__receive_buffer = self.__receive_buffer[
chars_processed_successfully + 1 :
]
self.__receive_buffer = self.__receive_buffer[chars_processed_successfully:]
can_message = (
None
if len(self.__message_buffer) == 0
Expand Down

0 comments on commit 9a8dbd6

Please sign in to comment.