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 == []