Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

getresources returns nothing for types created with Generic.create since 0.7.2

Aperta Adatta ai principianti
#151 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
86/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ruby
Ambito
networking

Direzione di ricerca

Inizia eseguendo la riproduzione fornita senza rete e ispeziona DNS#extract_resources, in particolare entrambi i rami che selezionano le risposte in base alla typeclass. Verifica che getresources restituisca il record Generic decodificato, mentre i record denominati IN::A e IN::AAAA mantengano il comportamento esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Ruby
Stelle
56
Fork
41
Merge medio
2h 50m
PR unite (30g)
8

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/resolv

Tutte le issue di ruby/resolv

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.