Skip to content

Commit 6b8a6d8

Browse files
committed
Ignore invalid address manager and link key entries
1 parent 5a4eb51 commit 6b8a6d8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

zigpy_znp/znp/security.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ async def read_devices(znp: ZNP) -> typing.Sequence[StoredDevice]:
282282
t.AddrMgrUserType.Assoc | t.AddrMgrUserType.Security,
283283
t.AddrMgrUserType.Security,
284284
):
285+
if not 0x0000 <= entry.nwkAddr <= 0xFFF7:
286+
LOGGER.warning("Ignoring invalid address manager entry: %s", entry)
287+
continue
288+
285289
devices[entry.extAddr] = StoredDevice(
286290
ieee=entry.extAddr,
287291
nwk=entry.nwkAddr,
@@ -290,6 +294,16 @@ async def read_devices(znp: ZNP) -> typing.Sequence[StoredDevice]:
290294
raise ValueError(f"Unexpected entry type: {entry.type}")
291295

292296
async for ieee, tx_ctr, rx_ctr, key in read_hashed_link_keys(znp, tclk_seed):
297+
if ieee not in devices:
298+
LOGGER.warning(
299+
"Skipping hashed link key %s (tx: %s, rx: %s) for unknown device %s",
300+
":".join(f"{b:02x}" for b in key),
301+
tx_ctr,
302+
rx_ctr,
303+
ieee,
304+
)
305+
continue
306+
293307
devices[ieee] = devices[ieee].replace(
294308
tx_counter=tx_ctr,
295309
rx_counter=rx_ctr,
@@ -298,6 +312,16 @@ async def read_devices(znp: ZNP) -> typing.Sequence[StoredDevice]:
298312
)
299313

300314
async for ieee, tx_ctr, rx_ctr, key in read_unhashed_link_keys(znp, addr_mgr):
315+
if ieee not in devices:
316+
LOGGER.warning(
317+
"Skipping unhashed link key %s (tx: %s, rx: %s) for unknown device %s",
318+
":".join(f"{b:02x}" for b in key),
319+
tx_ctr,
320+
rx_ctr,
321+
ieee,
322+
)
323+
continue
324+
301325
devices[ieee] = devices[ieee].replace(
302326
tx_counter=tx_ctr,
303327
rx_counter=rx_ctr,

0 commit comments

Comments
 (0)