Skip to content

Commit

Permalink
Drop empty frames (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly authored Dec 11, 2023
1 parent 1ac01ed commit 15b3223
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ def frame_received(self, data: bytes) -> None:
LOGGER.debug("Ignoring frame, protocol is not configured: %r", data)
return

if not data:
LOGGER.debug("Ignoring empty frame")
return

self._protocol(data)

async def get_board_info(
Expand Down
9 changes: 9 additions & 0 deletions tests/test_ezsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,12 @@ async def test_reset_custom_eui64(ezsp_f):
assert ezsp_f.setTokenData.mock_calls == [
call(t.NV3KeyId.CREATOR_STACK_RESTORED_EUI64, 0, t.LVBytes32(b"\xFF" * 8))
]


def test_empty_frame_received(ezsp_f):
"""Test dropping of invalid, empty frames."""
ezsp_f._protocol = MagicMock(spec_set=ezsp_f._protocol)
ezsp_f._protocol.__call__ = MagicMock()
ezsp_f.frame_received(b"")

assert ezsp_f._protocol.__call__.mock_calls == []

0 comments on commit 15b3223

Please sign in to comment.