Skip to content

Commit 73757bc

Browse files
committed
19852 FIX bgp_peer: tolerate unexpected address byte-list lengths
SNMP devices may return BGP peer address byte-lists whose length is neither 4 (IPv4) nor 16 (IPv6). The bgp_peer parser unconditionally tried to format such short byte strings as IPv6, which crashed with AddressValueError: At least 3 parts expected in '7c30' and aborted section parsing. _convert_address now renders unexpected byte-list lengths as unknown(...) so parsing continues for the remaining peers. Crash-Group-ID: 3608 Jira: CMK-33980 Change-Id: I12cbeb43eba0c9fa1bf1c186f64566d7b563c31d
1 parent 5e6caf2 commit 73757bc

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

.werks/19852.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[//]: # (werk v3)
2+
# bgp_peer: tolerate unexpected address byte-list lengths
3+
4+
key | value
5+
---------- | ---
6+
date | 2026-04-23T08:02:53.305241+00:00
7+
version | 2.6.0b1
8+
class | fix
9+
edition | community
10+
component | checks
11+
level | 1
12+
compatible | yes
13+
14+
SNMP devices may return BGP peer address byte-lists whose length is neither
15+
4 (IPv4) nor 16 (IPv6). The `bgp_peer` parser unconditionally tried to
16+
format such short byte strings as IPv6, which crashed with
17+
`AddressValueError: At least 3 parts expected in '7c30'` and aborted
18+
section parsing.
19+
20+
`_convert_address` now renders unexpected byte-list lengths as
21+
`unknown(...)` so parsing continues for the remaining peers.

cmk/plugins/collection/agent_based/bgp_peer.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,17 @@ def _convert_address(value: str | list[int]) -> str:
270270
if not value:
271271
return "empty()"
272272
if isinstance(value, list):
273-
return clean_v4_address(value) if len(value) == 4 else clean_v6_address(value)
273+
if len(value) == 4:
274+
return clean_v4_address(value)
275+
if len(value) == 16:
276+
return clean_v6_address(value)
277+
return f"unknown({value!r})"
274278
split_value = value.split(".")
275-
return clean_v4_address(split_value) if len(split_value) == 4 else clean_v6_address(split_value)
279+
if len(split_value) == 4:
280+
return clean_v4_address(split_value)
281+
if len(split_value) == 16:
282+
return clean_v6_address(split_value)
283+
return f"unknown({value!r})"
276284

277285

278286
def _format_last_received_error(error_entry: str | list[int]) -> str:

tests/unit/cmk/plugins/collection/agent_based/test_bgp_peer.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,8 @@ def test_bgp_peer_parse_cisco_2(data: StringByteTable, result: bgp_peer.Section)
200200
assert bgp_peer.parse_bgp_peer_cisco_2([data]) == result
201201

202202

203-
@pytest.mark.xfail(
204-
strict=True,
205-
reason="Crash group 3608: AddressValueError on short byte list",
206-
)
207203
def test_convert_address_short_byte_list() -> None:
208-
# SNMP may return a byte-list whose length is neither 4 (IPv4) nor 16
209-
# (IPv6). _convert_address must not crash on such malformed input.
210-
bgp_peer._convert_address([0x7C, 0x30])
204+
assert bgp_peer._convert_address([0x7C, 0x30]) == "unknown([124, 48])"
211205

212206

213207
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)