Skip to content

Compressed IPv6 addresses are corrupted by xform_net_address #355

Closed

Description

@somethingwithproof

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:

string(11) "2001:db8::1"

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.

Activity

  1. somethingwithproof commented on Nov 9, 2026

    @somethingwithproof
    MemberAuthor

    Still reproduces on develop at 867ca5b: 2001:db8::1 becomes 8193.3512.0.1. #356 (binary addresses truncated by trim()) and #351 item 2 (trim(null)) are in the same function, so these should be fixed and tested together.

  2. somethingwithproof commented on Nov 9, 2026

    @somethingwithproof
    MemberAuthor

    Proposed check order for xform_net_address(), covering this issue, #356 and #351 item 2 in one change. Raw binary values are converted before any trim(), and valid IP text is returned before the legacy hexadecimal conversion runs.

    flowchart TD
      in["Value from SNMP"] --> b4{"4 bytes and not<br/>valid IP text?"}
      b4 -- "Yes" --> v4["Convert to dotted IPv4"]
      b4 -- "No" --> b16{"16 bytes and not<br/>valid IP text?"}
      b16 -- "Yes" --> v6["Convert to IPv6 text"]
      b16 -- "No" --> t["Cast to string, then trim"]
      t --> ok{"Valid IPv4 or IPv6 text?"}
      ok -- "Yes" --> keep["Return unchanged"]
      ok -- "No" --> hex["Legacy hexadecimal conversion"]
    
    Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

QABug found in QAbug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions