File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -203,9 +203,10 @@ def _uncached_parse_advertisement_bytes(
203203 offset += 1 + length
204204 if end > total_length or end - start <= 0 :
205205 _LOGGER .debug (
206- "Invalid BLE GAP AD structure at offset %s: %s (%s)" ,
206+ "Invalid BLE GAP AD structure at offset %s: %s (length= %s)" ,
207207 offset ,
208208 gap_bytes ,
209+ length ,
209210 )
210211 continue
211212 if gap_type_num == TYPE_SHORT_LOCAL_NAME and local_name is None :
Original file line number Diff line number Diff line change @@ -563,6 +563,19 @@ def test_out_of_bounds_length():
563563 )
564564
565565
566+ def test_invalid_ad_debug_log_renders_without_error (caplog ):
567+ """Malformed AD must produce a renderable debug log (regression: format-string mismatch)."""
568+ # length=5 (claims 4 payload bytes after the type byte) but only 2 follow.
569+ # Unique payload so the lru_cache doesn't return a previous result.
570+ data = b"\x05 \x09 \xab \xcd "
571+ with caplog .at_level ("DEBUG" , logger = "bluetooth_data_tools.gap" ):
572+ adv = parse_advertisement_data ((data ,))
573+ assert adv .local_name is None
574+ # Render every captured record — a format-string mismatch raises here.
575+ messages = [r .getMessage () for r in caplog .records ]
576+ assert any ("Invalid BLE GAP AD structure" in m for m in messages )
577+
578+
566579def test_out_of_bounds_length_by_one ():
567580 """Test out of bound length by one."""
568581
You can’t perform that action at this time.
0 commit comments