Skip to content

fix: three regressions from #342 and #334 - #354

Open
somethingwithproof wants to merge 7 commits into
Cacti:developfrom
somethingwithproof:fix/mactrack-342-334-regressions
Open

fix: three regressions from #342 and #334#354
somethingwithproof wants to merge 7 commits into
Cacti:developfrom
somethingwithproof:fix/mactrack-342-334-regressions

Conversation

@somethingwithproof

Copy link
Copy Markdown
Member

Three regressions found while verifying #345 against a real Cacti 1.2.31 install. All three are fallout from recent merges, and each is filed separately with its evidence.

Merge order: this goes after #345. That PR restores Net/, without which the resolver cannot load at all, and it touches a different part of mactrack_resolver.php. The two merge cleanly but this branch is pointless before it.

Addresses with no PTR record are re-queried forever, #353

mactrack_resolver.php did $resp->answer[0]->ptrdname with no guard. A NOERROR response with an empty answer section is the normal reply for an address with no PTR record, and it is not an exception, so the catch (Net_DNS2_Exception $e) never ran. Against a live resolver with the bundled 1.5.5:

1.1.1.1         (has a PTR)      rcode=0  answer_count=1  answer[0] set
cloudflare.com  (NODATA, no PTR) rcode=0  answer_count=0  answer[0] UNSET

The row was then stored with an empty dns_hostname, which the selection query eleven lines above picks straight back up, so the same address was queried on every pass. Internal ranges without reverse DNS are the common case.

Newly reachable: before #342 the $use_resolver branches were inverted, so anyone with nameservers configured fell through to gethostbyaddr() and never entered this path.

The same block had a second fault. The catch branch assigned gethostbyaddr() directly and, unlike the else branch below it, never fell back to the address when that returned false, so those rows looped too. Both now fall back the same way.

An empty hardware address is stored as the string NOT USER, #350

xform_mac_address() returned '' for empty input for twenty years, because the trailing str_replace() overwrote the placeholder the dead branch built. #342 removed the overwrite and the placeholder became live. mac_track_interfaces.ifPhysAddress is a MAC column, and a VLAN SVI, loopback or tunnel reports an empty address, so the Interfaces view and its CSV export show NOT USER where the cell used to be blank.

The port name filter drops punctuation, #349

#334 put port_name_filter through sanitize_search_string, which deletes ( ) and replaces , + [ ] { } and others with spaces:

AP-3 (2nd floor)  ->  AP-3 2nd floor
Uplink,Core       ->  Uplink Core
Gi1/0/1           ->  Gi1/0/1          (unchanged)

The value feeds mtp.port_name = db_qstr(...) and a LIKE prefix, so an exact match on a description containing punctuation could never succeed. All ten consumers across mactrack_view_macs.php and mactrack_view_dot1x.php were already bound through db_qstr() before #334 (commit f02d27d), so the sanitiser added no protection, only breakage. Reverted to FILTER_DEFAULT for this field; ip_filter and mac_filter keep theirs, since :, -, . and digits survive intact.

Verification

Disposable Cacti 1.2.31 + MariaDB 10.11, installed with cli/install_cacti.php and cli/plugin_manage.php:

tests/e2e/test_xform_mac_address.php     OK
mactrack_view_macs.php                   HTTP 200
mactrack_view_dot1x.php                  HTTP 200
PTR NODATA                               old=NULL  new='' then gethostbyaddr, then the address
port_name_filter 'AP-3 (2nd floor)'      preserved intact

The new test was checked against a reverted fix before being trusted:

with the fix reverted:  Empty ifPhysAddress '' became 'NOT USER'   exit 1
with the fix in place:  OK                                          exit 0

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Copilot AI lite review requested due to automatic review settings September 5, 2026 09:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

xform_mac_address() still uses default trim() which strips NUL bytes and can corrupt binary SNMP MACs ending in 00, and the test suite should cover that edge case.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes three regressions introduced by recent mactrack changes and observed on a real Cacti 1.2.31 install: (1) reverse-DNS “NODATA” results causing infinite re-query loops, (2) empty hardware addresses being stored as a placeholder string instead of remaining empty, and (3) port-name filtering breaking on punctuation and URL query-string characters.

Changes:

  • Make PTR resolution robust to NOERROR/NODATA responses and ensure unresolved IPs are stored in a way that prevents infinite re-processing.
  • Restore historical behavior for empty MAC addresses (store as empty string) and add/adjust tests around xform_mac_address().
  • Preserve punctuation in port_name_filter and URL-encode it in the JS filter application logic.
File summaries
File Description
tests/Pest/Unit/XformMacAddressTest.php Switch to testing the real xform_mac_address() and update expectations for empty-MAC behavior.
mactrack_view_macs.php Stop sanitizing punctuation out of port_name_filter and URL-encode the value in filter requests.
mactrack_view_dot1x.php Same port_name_filter punctuation preservation and URL-encoding as the MACs view.
mactrack_resolver.php Guard PTR response dereference and normalize unresolved outcomes to avoid endless retries.
lib/mactrack_h3c_3com.php Avoid indexing missing MAC entries and skip DB lookups when MAC is empty.
lib/mactrack_functions.php Restore empty-MAC transformation to '' (instead of a placeholder).
CHANGELOG.md Document the three regression fixes.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/mactrack_functions.php Outdated
Comment thread tests/Pest/Unit/XformMacAddressTest.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants