diff --git a/custom_components/myhome/gateway_sessions.py b/custom_components/myhome/gateway_sessions.py index 5df70c70..8faef4e8 100644 --- a/custom_components/myhome/gateway_sessions.py +++ b/custom_components/myhome/gateway_sessions.py @@ -526,7 +526,7 @@ def _is_status_report_item(item: Any) -> bool: ) -_WHO4_QUERY_RE = re.compile(r"^\*#4\*(?P[^#*]+(?:#[^*]+)*)(?:\*(?P\d+))?##$") +_WHO4_QUERY_RE = re.compile(r"^\*#4\*(?P[^#*]+(?:#[^#*]+)*)(?:\*(?P\d+))?##$") _WHO4_REPLY_RE = re.compile( r"^\*(?:#4\*(?P[^*]+)\*.*|4\*[^*]+\*(?P[^*]+))##$" ) diff --git a/tests/test_issue_886_myhomeserver1_41_zones.py b/tests/test_issue_886_myhomeserver1_41_zones.py index 6b6a59eb..0c491928 100644 --- a/tests/test_issue_886_myhomeserver1_41_zones.py +++ b/tests/test_issue_886_myhomeserver1_41_zones.py @@ -588,6 +588,15 @@ async def test_pause_status_edge_cases_and_mixed_non_who4_collected_frames( _mismatched_who4_reply_zones("*#4*60##", ["*1*1*11##", "*#4*34*0*0146##"]) == {"34"} ) + # Multi-segment WHERE (`#4#01`) and linear-time rejection of malformed `#`-repeated input (CodeQL py/redos) + assert ( + _mismatched_who4_reply_zones("*#4*60#4#01*60##", ["*#4*34#4#01*60*55##"]) + == {"34"} + ) + assert ( + _mismatched_who4_reply_zones("*#4*1" + "#a" * 40 + "!", ["*#4*34*0*0146##"]) + is None + ) scheduler = FrameScheduler() try: