Skip to content

Commit

Permalink
config read from file should return frozen data!
Browse files Browse the repository at this point in the history
  • Loading branch information
HoneyryderChuck committed Nov 15, 2024
1 parent c4837aa commit 3cf932e
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -980,13 +980,13 @@ def Config.parse_resolv_conf(filename)
next unless keyword
case keyword
when 'nameserver'
nameserver.concat(args)
nameserver.concat(args.each(&:freeze))
when 'domain'
next if args.empty?
search = [args[0]]
search = [args[0].freeze]
when 'search'
next if args.empty?
search = args
search = args.each(&:freeze)
when 'options'
args.each {|arg|
case arg
Expand All @@ -997,22 +997,22 @@ def Config.parse_resolv_conf(filename)
end
}
}
return { :nameserver => nameserver, :search => search, :ndots => ndots }
return { :nameserver => nameserver.freeze, :search => search.freeze, :ndots => ndots.freeze }.freeze
end

def Config.default_config_hash(filename="/etc/resolv.conf")
if File.exist? filename
config_hash = Config.parse_resolv_conf(filename)
Config.parse_resolv_conf(filename)
elsif /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
require 'win32/resolv'
search, nameserver = Win32::Resolv.get_resolv_info
config_hash = {}
config_hash[:nameserver] = nameserver if nameserver
config_hash[:search] = [search].flatten if search
config_hash
else
if /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
require 'win32/resolv'
search, nameserver = Win32::Resolv.get_resolv_info
config_hash = {}
config_hash[:nameserver] = nameserver if nameserver
config_hash[:search] = [search].flatten if search
end
{}
end
config_hash || {}
end

def lazy_initialize
Expand Down

0 comments on commit 3cf932e

Please sign in to comment.