From ef5b7f1a54671369a8b714d3aff378da70aa3f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20L=C3=B6nnemark?= <ketl@nsc.liu.se> Date: Fri, 8 Sep 2023 17:38:46 +0200 Subject: [PATCH] resolve_ipnets(): Canonicalize resolved addresses The version of JRuby included with puppetserver (as of 7.9.5) does not canonicalize IPv6 addresses returned by Socket.getaddrinfo, and thus returns them without compressing runs of zeros. For example, running resolve_ipnets under puppetserver would return 2001:0db8:0:0:0:0:0:1 if running server-less returned 2001:0db8::1. Work around the issue by converting resolved addresses to IPAddr objects, then back to strings. --- lib/puppet/parser/functions/resolve_ipnets.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/resolve_ipnets.rb b/lib/puppet/parser/functions/resolve_ipnets.rb index 3405867..1658879 100644 --- a/lib/puppet/parser/functions/resolve_ipnets.rb +++ b/lib/puppet/parser/functions/resolve_ipnets.rb @@ -103,7 +103,11 @@ module Puppet::Parser::Functions ips[info[4]] = [] found_families << info[4] end - ips.fetch(info[4]) << info[3] + # Canonicalize address using IPAddr so the same representation + # is returned regardless of interpreter. + # JRuby's Socket.getaddrinfo returns IPv6 addresses without + # compressed zeros, while CRuby's does compress zeros. + ips.fetch(info[4]) << IPAddr.new(info[3]).to_s end end ipaddrs = [ ] -- GitLab