1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2026-04-03 17:44:07 +02:00

fix: use [2:] instead of lstrip('0x') to strip hex prefix in ifconfig parser

str.lstrip('0x') strips any combination of '0' and 'x' characters from
the left, not the literal two-character prefix '0x'. For subnet masks
where the hex digits start with '0' (e.g. '0x00000000' for a /0 mask),
lstrip strips all leading zeros along with the 'x', producing an empty
string instead of '00000000'.

Replace with a slice [2:] which correctly removes exactly the first two
characters ('0x') regardless of what follows.

This bug affected both the legacy ipv4_mask field and the ipv4[] list
items in _process() (lines 267 and 292).

Fixes #685
This commit is contained in:
Julio César Suástegui
2026-03-30 03:07:11 -06:00
parent 9fd13e6987
commit 56bd860a5e

View File

@@ -264,7 +264,7 @@ def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]:
try:
if entry['ipv4_mask'].startswith('0x'):
new_mask = entry['ipv4_mask']
new_mask = new_mask.lstrip('0x')
new_mask = new_mask[2:]
new_mask = '.'.join(str(int(i, 16)) for i in [new_mask[i:i + 2] for i in range(0, len(new_mask), 2)])
entry['ipv4_mask'] = new_mask
except (ValueError, TypeError, AttributeError):
@@ -289,7 +289,7 @@ def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]:
try:
if ip_address['mask'].startswith('0x'):
new_mask = ip_address['mask']
new_mask = new_mask.lstrip('0x')
new_mask = new_mask[2:]
new_mask = '.'.join(str(int(i, 16)) for i in [new_mask[i:i + 2] for i in range(0, len(new_mask), 2)])
ip_address['mask'] = new_mask
except (ValueError, TypeError, AttributeError):