From 15b3223def5b1b47dd0728a4cc7e9549f0f50899 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:32:50 -0500 Subject: [PATCH] Drop empty frames (#600) --- bellows/ezsp/__init__.py | 4 ++++ tests/test_ezsp.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/bellows/ezsp/__init__.py b/bellows/ezsp/__init__.py index 2402cd79..b444d5c6 100644 --- a/bellows/ezsp/__init__.py +++ b/bellows/ezsp/__init__.py @@ -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( diff --git a/tests/test_ezsp.py b/tests/test_ezsp.py index 19f97691..6b5c1e96 100644 --- a/tests/test_ezsp.py +++ b/tests/test_ezsp.py @@ -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 == []