Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport patch to resolv for underqualified domain names #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/logstash/filters/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "lru_redux"
require "resolv"
require "timeout"
require "logstash/filters/resolv_patch"
require "logstash/filters/dns/resolv_patch"

java_import 'java.net.IDN'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "resolv"

jruby_gem_version = Gem::Version.new(JRUBY_VERSION)

# ref: https://github.com/logstash-plugins/logstash-filter-dns/issues/40
#
# JRuby 9k versions prior to 9.1.16.0 have a bug which crashes IP address
Expand All @@ -10,10 +12,7 @@
#
# The code below is copied from JRuby 9.1.16.0 resolv.rb:
# https://github.com/jruby/jruby/blob/9.1.16.0/lib/ruby/stdlib/resolv.rb#L775-L784

JRUBY_GEM_VERSION = Gem::Version.new(JRUBY_VERSION)

if JRUBY_GEM_VERSION >= Gem::Version.new("9.1.13.0") && JRUBY_GEM_VERSION < Gem::Version.new("9.1.16.0")
if jruby_gem_version >= Gem::Version.new("9.1.13.0") && jruby_gem_version < Gem::Version.new("9.1.16.0")
class Resolv
class DNS
class Requester
Expand All @@ -32,4 +31,29 @@ def sender(msg, data, host, port=Port)
end
end
end
end
end

# JRuby 1.x ships with a Ruby stdlib that has a bug in its resolv implementation
# in which it fails to correctly canonicalise unqualified or underqualified
# domains (e.g., domain names with fewer than the configured ndots, which defaults
# to 1).
#
# See: https://bugs.ruby-lang.org/issues/10412
#
# Conditionally apply the patch to the method definition by wrapping it at runtime.
if jruby_gem_version < Gem::Version.new("9.0")
class Resolv::DNS
class Config
alias generate_candidates_without_toplevel generate_candidates
def generate_candidates_with_toplevel(name)
candidates = generate_candidates_without_toplevel(name)
fname = Name.create("#{name}.")
if !candidates.include?(fname)
candidates << fname
end
candidates
end
alias generate_candidates generate_candidates_with_toplevel
end
end
end