Describe the bug
xform_net_address() converts valid short/compressed IPv6 text as though it were a colon-delimited hexadecimal IPv4 value.
For example, 2001:db8::1 becomes 8193.3512.0.1. The function currently assumes any colon-delimited input with a string length of 11 characters or fewer is hexadecimal IPv4.
To reproduce
Run from the plugin root:
php -r "require 'tests/bootstrap.php'; require 'lib/mactrack_functions.php'; var_dump(xform_net_address('2001:db8::1'));"
Observed:
string(15) "8193.3512.0.1"
Expected:
The behavior was reproduced in clean PHP 8.1, 8.2, 8.3, and 8.4 Docker containers while building the cohesive MacTrack test suite.
Suggested direction
Recognize valid IPv6 text (for example with filter_var(..., FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) before applying the legacy hexadecimal IPv4 conversion.
Describe the bug
xform_net_address()converts valid short/compressed IPv6 text as though it were a colon-delimited hexadecimal IPv4 value.For example,
2001:db8::1becomes8193.3512.0.1. The function currently assumes any colon-delimited input with a string length of 11 characters or fewer is hexadecimal IPv4.To reproduce
Run from the plugin root:
php -r "require 'tests/bootstrap.php'; require 'lib/mactrack_functions.php'; var_dump(xform_net_address('2001:db8::1'));"Observed:
Expected:
The behavior was reproduced in clean PHP 8.1, 8.2, 8.3, and 8.4 Docker containers while building the cohesive MacTrack test suite.
Suggested direction
Recognize valid IPv6 text (for example with
filter_var(..., FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) before applying the legacy hexadecimal IPv4 conversion.