logstash-filter-dns 3.1.2 → 3.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ee891cdca96c9fc77706efc72b6d33931c261fe000d1ccd2bfd77f4649544a0
4
- data.tar.gz: dbf27cff110158f8f0a69a31826a1817929115461816d405c6494138ad99fe29
3
+ metadata.gz: 42e105e5fc1ecf91266bcd1497c8ea82ac0b0224b26980c9c4cce814b1f2ec14
4
+ data.tar.gz: 96585aa3899ec180dc844cd4b9e4197e42052fd6054de5e206d1c9c11e2efc1d
5
5
  SHA512:
6
- metadata.gz: 5ef252d8dd5e6d990182b036c09f47ae9326b7af4e1ccb6dcae37d1de86fa52c6972308cf386bd735ea977c9cf3087fcecb523980807d67b4df4ceed27092018
7
- data.tar.gz: 81392b44caeab24cdc0f7105795fb952890a384256f369c9a637b5bb93e8c60e8aaa1d03c86f01ce8028406dfde3f8c3608cf340d56585f915147cd7bf232fa3
6
+ metadata.gz: 61b22319a08350fb1c33199332217bf54cee91989e1a2bfc03cf80c7c2a5e785056da4d0f0a2dafdcd2821147982f5c50e638e79478f1b8f7b1a0ff507dfdd33
7
+ data.tar.gz: bb8fa5118a9a2ee2f32f736ecc7fccbea4362dc2966edb36f50e40eb8eb1569af33a1df9945c027a6a5cefae8ec718b3ae98acf7bca772dbf220ff7bf1ff01cb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.1.3
2
+ - Fixed an issue where each missed lookup could result in unreclaimed memory ([jruby bug](https://github.com/jruby/jruby/issues/6015)) by handling lookup misses without raising exceptions [#61](https://github.com/logstash-plugins/logstash-filter-dns/pull/61)
3
+
1
4
  ## 3.1.2
2
5
  - Added restriction on JRuby resolv.rb patch to versions prior to 9.2.9.0 [#58](https://github.com/logstash-plugins/logstash-filter-dns/pull/58)
3
6
 
@@ -195,11 +195,12 @@ class LogStash::Filters::DNS < LogStash::Filters::Base
195
195
  else
196
196
  address = retriable_getaddress(raw)
197
197
  end
198
- rescue Resolv::ResolvError => e
199
- @failed_cache[raw] = true if @failed_cache
200
- @logger.debug("DNS: couldn't resolve the hostname.",
201
- :field => field, :value => raw, :message => e.message)
202
- return
198
+ if address.nil?
199
+ @failed_cache[raw] = true if @failed_cache
200
+ @logger.debug("DNS: couldn't resolve the hostname.",
201
+ :field => field, :value => raw)
202
+ return
203
+ end
203
204
  rescue Resolv::ResolvTimeout, Timeout::Error
204
205
  @failed_cache[raw] = true if @failed_cache
205
206
  @logger.warn("DNS: timeout on resolving the hostname.",
@@ -275,11 +276,12 @@ class LogStash::Filters::DNS < LogStash::Filters::Base
275
276
  else
276
277
  hostname = retriable_getname(raw)
277
278
  end
278
- rescue Resolv::ResolvError => e
279
- @failed_cache[raw] = true if @failed_cache
280
- @logger.debug("DNS: couldn't resolve the address.",
281
- :field => field, :value => raw, :message => e.message)
282
- return
279
+ if hostname.nil?
280
+ @failed_cache[raw] = true if @failed_cache
281
+ @logger.debug("DNS: couldn't resolve the address.",
282
+ :field => field, :value => raw)
283
+ return
284
+ end
283
285
  rescue Resolv::ResolvTimeout, Timeout::Error
284
286
  @failed_cache[raw] = true if @failed_cache
285
287
  @logger.warn("DNS: timeout on resolving address.",
@@ -350,13 +352,43 @@ class LogStash::Filters::DNS < LogStash::Filters::Base
350
352
 
351
353
  private
352
354
  def getname(address)
353
- name = @resolv.getname(address).force_encoding(Encoding::UTF_8)
354
- IDN.toUnicode(name)
355
+ name = resolv_getname_or_nil(@resolv, address)
356
+ name && name.force_encoding(Encoding::UTF_8)
357
+ name && IDN.toUnicode(name)
355
358
  end
356
359
 
357
360
  private
358
361
  def getaddress(name)
359
362
  idn = IDN.toASCII(name)
360
- @resolv.getaddress(idn).force_encoding(Encoding::UTF_8)
363
+ address = resolv_getaddress_or_nil(@resolv, idn)
364
+ address && address.force_encoding(Encoding::UTF_8)
365
+ end
366
+
367
+ private
368
+ def resolv_getname_or_nil(resolver, address)
369
+ # `Resolv#each_name` yields to the provided block zero or more times;
370
+ # to prevent it from yielding multiple times when more than one match
371
+ # is found, we return directly in the block.
372
+ # See also `Resolv#getname`
373
+ resolver.each_name(address) do |name|
374
+ return name
375
+ end
376
+
377
+ # If no match was found, we return nil.
378
+ return nil
379
+ end
380
+
381
+ private
382
+ def resolv_getaddress_or_nil(resolver, name)
383
+ # `Resolv#each_address` yields to the provided block zero or more times;
384
+ # to prevent it from yielding multiple times when more than one match
385
+ # is found, we return directly in the block.
386
+ # See also `Resolv#getaddress`
387
+ resolver.each_address(name) do |address|
388
+ return address
389
+ end
390
+
391
+ # If no match was found, we return nil.
392
+ return nil
361
393
  end
362
394
  end # class LogStash::Filters::DNS
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-dns'
4
- s.version = '3.1.2'
4
+ s.version = '3.1.3'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Performs a standard or reverse DNS lookup"
7
7
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -6,13 +6,16 @@ require "resolv"
6
6
  describe LogStash::Filters::DNS do
7
7
  describe "with stubbed Resolv" do
8
8
  before(:each) do
9
- allow_any_instance_of(Resolv).to receive(:getaddress).with("carrera.databits.net").and_return("199.192.228.250")
10
- allow_any_instance_of(Resolv).to receive(:getaddress).with("does.not.exist").and_raise(Resolv::ResolvError)
11
- allow_any_instance_of(Resolv).to receive(:getaddress).with("nonexistanthostname###.net").and_raise(Resolv::ResolvError)
12
- allow_any_instance_of(Resolv).to receive(:getname).with("199.192.228.250").and_return("carrera.databits.net")
13
- allow_any_instance_of(Resolv).to receive(:getname).with("127.0.0.1").and_return("localhost")
14
- allow_any_instance_of(Resolv).to receive(:getname).with("128.0.0.1").and_raise(Resolv::ResolvError)
15
- allow_any_instance_of(Resolv).to receive(:getname).with("199.192.228.250").and_return("carrera.databits.net")
9
+ # We use `Resolv#each_address` and `Resolv#each_name`, which have
10
+ # undefined return values but _yield_ once per result, so our stubs
11
+ # need to either yield a result or not yield at all if there is no result.
12
+ allow_any_instance_of(Resolv).to receive(:each_address).with("carrera.databits.net").and_yield("199.192.228.250")
13
+ allow_any_instance_of(Resolv).to receive(:each_address).with("does.not.exist") # no yield
14
+ allow_any_instance_of(Resolv).to receive(:each_address).with("nonexistanthostname###.net") # no yield
15
+ allow_any_instance_of(Resolv).to receive(:each_name).with("199.192.228.250").and_yield("carrera.databits.net")
16
+ allow_any_instance_of(Resolv).to receive(:each_name).with("127.0.0.1").and_yield("localhost")
17
+ allow_any_instance_of(Resolv).to receive(:each_name).with("128.0.0.1") # no yield
18
+ allow_any_instance_of(Resolv).to receive(:each_name).with("199.192.228.250").and_yield("carrera.databits.net")
16
19
  end
17
20
 
18
21
  describe "dns reverse lookup, replace (on a field)" do
@@ -305,7 +308,7 @@ describe LogStash::Filters::DNS do
305
308
  let(:event2) { LogStash::Event.new("message" => "unkownhost") }
306
309
 
307
310
  before(:each) do
308
- allow(subject).to receive(:getaddress).and_raise Resolv::ResolvError
311
+ allow(subject).to receive(:getaddress).and_return(nil)
309
312
  subject.register
310
313
  end
311
314
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-dns
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-21 00:00:00.000000000 Z
11
+ date: 2020-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement