zerotier-members: validate hex input to prevent ValueError

Add proper validation for network_id and identity parameters to ensure
they contain valid hexadecimal characters. Previously, non-hex input
would raise ValueError instead of the expected ClanError, bypassing
proper error handling.
This commit is contained in:
Jörg Thalheim
2025-08-25 14:04:25 +02:00
parent 23d11651fc
commit 7547761812

View File

@@ -17,8 +17,16 @@ def compute_zerotier_ip(network_id: str, identity: str) -> ipaddress.IPv6Address
if len(network_id) != 16: if len(network_id) != 16:
msg = f"network_id must be 16 characters long, got {network_id}" msg = f"network_id must be 16 characters long, got {network_id}"
raise ClanError(msg) raise ClanError(msg)
nwid = int(network_id, 16) try:
node_id = int(identity, 16) nwid = int(network_id, 16)
except ValueError:
msg = f"network_id must be a valid hexadecimal string, got {network_id}"
raise ClanError(msg) from None
try:
node_id = int(identity, 16)
except ValueError:
msg = f"identity must be a valid hexadecimal string, got {identity}"
raise ClanError(msg) from None
addr_parts = bytearray( addr_parts = bytearray(
[ [
0xFD, 0xFD,