From 6680455346d64d4e236078a7d8ae849f633e23b1 Mon Sep 17 00:00:00 2001 From: Ericky Dos Santos Date: Fri, 6 Nov 2026 11:02:19 -0500 Subject: [PATCH] Don't crash on nameservers Net::IP can't parse Net::IP->new() returns undef for a scoped address such as fe80::1%eth0, which made the IPv4-mapping workaround for the Net::DNS bugs die with "Can't call method "version" on an undefined value". Such nameservers are common on networks that hand out link-local DNS servers through RDNSS or DHCPv6. Strip any zone index before asking Net::IP for the address family, and pass through unchanged any nameserver it still can't parse. Likewise, skip with a warning, rather than crash on, any address in the output of 'ip -6 address list' that Net::IP can't parse. --- clatd | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/clatd b/clatd index 2ed59f6..8c2bb2e 100755 --- a/clatd +++ b/clatd @@ -354,8 +354,11 @@ sub get_plat_prefix_from_dns64 { # an IPv4 name server (e.g., systemd-resolved listening on 127.0.0.53). # This works around https://rt.cpan.org/Public/Bug/Display.html?id=158714 # (and/or https://rt.cpan.org/Public/Bug/Display.html?id=132760). + # Net::IP can't parse a scoped address such as fe80::1%eth0, so strip + # the zone index first, and leave any address it still can't parse as-is. $res->nameservers(map { - Net::IP->new($_)->version() == 4 ? "::ffff:$_" : $_; + my $ip = Net::IP->new((split(/%/, $_))[0]); + $ip && $ip->version() == 4 ? "::ffff:$_" : $_; } $res->nameservers); d2("Nameservers after Net::DNS bug workaround: ", join(" ", $res->nameservers)); @@ -564,7 +567,12 @@ sub get_clat_v6_addr { my $candidate = $1; my $plen = $2; d2("Saw a candidate address on '$plat_dev': $candidate/$plen"); - my $candidate_int = Net::IP->new($candidate, 6)->intip(); + my $candidate_ip = Net::IP->new($candidate, 6); + if(!$candidate_ip) { + w("Ignoring unparseable address '$candidate' on '$plat_dev'"); + next; + } + my $candidate_int = $candidate_ip->intip(); if(!$candidate_int) { err("Failed to convert plat prefix to bigint"); }