ruby-dns / net-dns

Net::DNS is a DNS library written in Ruby.
http://net-dns.rubyforge.org
Other
165 stars 43 forks source link

Resolver() fails for TXT if upd package is larger than the packet_size constant #64

Open svenXY opened 10 years ago

svenXY commented 10 years ago

Hi,

I'm using a simple

require 'rubygems'
require 'net/dns'

res = Net::DNS::Resolver.new(
  :nameservers =>"172.11.11.11",                              
  :recursive => false,
   :retry       =>10)

packet = res.query('some.rr.with.lots.of.txt.lines', Net::DNS::TXT) 

This fails with

.../lib/ruby/gems/1.8/gems/net-dns-0.8.0/lib/net/dns/names.rb:30:in `dn_expand': Offset is greater than packet lenght!
...

Now, when setting a :packet_size of say 2048 in resolver.rb, all is fine. Unfortunately, :packet_size is not settable. Could this be changed by any chance?

Thanks and cheers, Sven

svenXY commented 10 years ago

I believe the attached patch will add the possibility to either set is with a res.packet_size = xxx or in the Resolver() constructor.

Cheers, Sven

--- lib/ruby/gems/1.8/gems/net-dns-0.8.0/lib/net/dns/resolver.rb.orig   2014-04-15 16:14:13.473223887 +0200
+++ lib/ruby/gems/1.8/gems/net-dns-0.8.0/lib/net/dns/resolver.rb        2014-04-15 16:31:08.989885451 +0200
@@ -392,6 +392,20 @@
         @config[:packet_size]
       end

+      # Set the defined size of packets.
+      def packet_size=(arg)
+        case arg
+        when String
+          @config[:packet_size] = arg.to_i
+          @logger.info "Packet size changed to value #{@config[:packet_size].inspect}"
+        when Fixnum
+          @config[:packet_size] = arg
+          @logger.info "Packet size changed to value #{@config[:packet_size].inspect}"
+        else
+          raise ArgumentError, "Wrong argument format, neither String that converts to Int, not Integer"
+        end
+
       # Get the port number to which the resolver sends queries.
       #
       #   puts "Sending queries to port #{res.port}"
ghost commented 10 years ago

I fixed this in my fork here: https://github.com/mordocai/net-dns/issues/1. The fix should be in the v0.8.3 release later this week along with many other fixes