From 06b7d5fff0f06e88d18b9b1f1b9d85c27b51ba64 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Mon, 25 Mar 2024 05:51:29 -0700 Subject: [PATCH] Patching resolv.rb to conditionally load Signed-off-by: John McCrae --- config/patches/ruby/ruby-win32_resolv.patch | 11 +++++++++++ config/software/ruby.rb | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 config/patches/ruby/ruby-win32_resolv.patch diff --git a/config/patches/ruby/ruby-win32_resolv.patch b/config/patches/ruby/ruby-win32_resolv.patch new file mode 100644 index 000000000..f2b4bb921 --- /dev/null +++ b/config/patches/ruby/ruby-win32_resolv.patch @@ -0,0 +1,11 @@ +--- C:\Ruby30-x64\lib\ruby\3.0.0\win32\resolv-orig.rb 2021-11-27 14:46:20 -0800 ++++ c:\Ruby30-x64\lib\ruby\3.0.0\win32\resolv.rb 2024-03-24 19:33:40 -0700 +@@ -4,7 +4,7 @@ + + =end + +-require 'win32/registry' ++require 'win32/registry' unless defined?(Win32::Registry) + + module Win32 + module Resolv diff --git a/config/software/ruby.rb b/config/software/ruby.rb index 4c685590e..0bff63c38 100644 --- a/config/software/ruby.rb +++ b/config/software/ruby.rb @@ -153,6 +153,19 @@ patch source: "ruby-win32_warning_removal.patch", plevel: 1, env: patch_env end + # We fixed a bug regarding Windows fqdn resolution in Ohai on the 17-stable branch. + # That Ohai update requires the Resolv class. The 'resolv' class unconditionally + # loads the Win32::Registry class as a dependency. + # Chef Infra already loads Win32::Registry and has a monkeypatch for the export_string method. + # When the Resolv class loads again in Ohai, it overwrites the monkeypatch and that + # leads to registry encoding/decoding errors - Base Ruby classes return text encoded in + # UTF-16LE format and we need UTF-8. + # Here we patch the Ruby Win32/Reolv.rb file to make reloading the Win32::Registry class + # conditional and therefore prevent the monkeypatch from being overwritten. + if windows? && version.satisfies?("~> 3.0.0") + patch source: "ruby-win32_resolv.patch", plevel: 1, env: patch_env + end + # RHEL6 has a base compiler that does not support -fstack-protector-strong, but we # cannot build modern ruby on the RHEL6 base compiler, and the configure script # determines that it supports that flag and so includes it and then ultimately