getresources returns nothing for types created with Generic.create since 0.7.2
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 86/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- ruby
- Lĩnh vực
- networking
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện không có mạng được cung cấp và kiểm tra DNS#extract_resources, đặc biệt là cả hai nhánh chọn các câu trả lời theo typeclass. Xác minh rằng getresources trả về bản ghi Generic đã được giải mã, trong khi các bản ghi IN::A và IN::AAAA có tên vẫn giữ nguyên hành vi hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Since 0.7.2, getresources and each_resource never return records for a type created with Resolv::DNS::Resource::Generic.create, for example NAPTR (type 35), which has no named class in Resolv.
Cause
fa5e689c4 ("Do not register on-demand classes for unknown DNS types and SvcParamKeys") stopped registering the classes from Generic.create. So decoding a reply gives each unknown record a new anonymous class, not the class the caller passed. 05185b432 and fcff0a19e updated Message#== and Generic#== for this with Generic.type_class_equal?. DNS#extract_resources still selects answers with when typeclass, so it drops every decoded record of such a type.
Reproduction
This needs no network: it encodes and decodes a reply and gives it to getresources.
require "resolv"
naptr = Resolv::DNS::Resource::Generic.create(35, Resolv::DNS::Resource::IN::ClassValue)
name = "example.com."
rdata = "\x00\x64\x00\x0A\x01U\x07E2U+sip\x1C!^.*$!sip:[email protected]!\x00".b
reply = Resolv::DNS::Message.new
reply.add_answer(name, 60, naptr.new(rdata))
decoded = Resolv::DNS::Message.decode(reply.encode)
dns = Resolv::DNS.new
dns.define_singleton_method(:fetch_resource) {|_name, _typeclass, &block| block.call(decoded, Resolv::DNS::Name.create(name)) }
puts "resolv #{Resolv::VERSION}: #{dns.getresources(name, naptr).size} record(s)"
resolv 0.7.0: 1 record(s)
resolv 0.7.2: 0 record(s)
resolv 0.8.0: 0 record(s)
A real query shows the same result: getresources returns [], but fetch_resource gets the NAPTR answer. Ruby 4.0.7 includes 0.7.2, so a patch update of Ruby is enough to get this behaviour.
Possible fix
Compare by type and class value in extract_resources, in both when typeclass branches:
- when typeclass
+ when ->(data) { Resource::Generic.type_class_equal?(data.class, typeclass) }
With this change, the reproduction returns 1 record on 0.8.0. Named types (IN::A, IN::AAAA) behave as before, because type_class_equal? compares identity first and returns false for classes that are not Generic.
Workaround
Register the type in the same way as Resolv's built-in types:
class NAPTR < Resolv::DNS::Resource::Generic
const_set(:TypeValue, 35)
const_set(:ClassValue, Resolv::DNS::Resource::IN::ClassValue)
Resolv::DNS::Resource::ClassHash[[self::TypeValue, self::ClassValue]] = self
end
- Ngôn ngữ chính
- Ruby
- Star
- 56
- Fork
- 41
- Merge trung bình
- 2 giờ 50 phút
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ruby/resolv
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
`resolv.conf` on macOS sometimes has interface suffix which breaks `resolve.rb`.Có thể làm lại được @ioquatix đã nhận 1251 ngày trước và không có pull request nào đang mở. Đang mở
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
misa.G should not be definedĐang mởdata error
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
riscv/riscv-unified-db#2648 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
P2 testing
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày