Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#151 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
86/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
ruby
領域
networking

調査の方向性

まず、提供されているネットワークなしの再現を実行し、DNS#extract_resources を調査します。特に、typeclass に基づいて回答を選択する両方の分岐を確認してください。getresources がデコードされた Generic レコードを返し、名前付きの IN::A および IN::AAAA レコードが既存の動作を維持することを検証してください。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Ruby
スター
56
フォーク
41
平均マージ
2時間 50分
マージ済み PR(30日)
8

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby/resolv のほかの issue

ruby/resolv の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。