Skip to content

Commit

Permalink
Merge pull request ruby#30 from hanazuki/srv-no-compress
Browse files Browse the repository at this point in the history
Do not compress domain name in SRV RDATA
  • Loading branch information
sorah authored Apr 8, 2023
2 parents 0c10845 + ac85724 commit 4ffac87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/resolv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1487,14 +1487,14 @@ def put_string_list(ds)
}
end

def put_name(d)
put_labels(d.to_a)
def put_name(d, compress: true)
put_labels(d.to_a, compress: compress)
end

def put_labels(d)
def put_labels(d, compress: true)
d.each_index {|i|
domain = d[i..-1]
if idx = @names[domain]
if compress && idx = @names[domain]
self.put_pack("n", 0xc000 | idx)
return
else
Expand Down Expand Up @@ -2328,7 +2328,7 @@ def encode_rdata(msg) # :nodoc:
msg.put_pack("n", @priority)
msg.put_pack("n", @weight)
msg.put_pack("n", @port)
msg.put_name(@target)
msg.put_name(@target, compress: false)
end

def self.decode_rdata(msg) # :nodoc:
Expand Down
8 changes: 8 additions & 0 deletions test/resolv/test_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ def test_hash
def test_coord
Resolv::LOC::Coord.create('1 2 1.1 N')
end

def test_srv_no_compress
# Domain name in SRV RDATA should not be compressed
issue29 = 'https://github.com/ruby/resolv/issues/29'
m = Resolv::DNS::Message.new(0)
m.add_answer('example.com', 0, Resolv::DNS::Resource::IN::SRV.new(0, 0, 0, 'www.example.com'))
assert_equal "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x07example\x03com\x00\x00\x21\x00\x01\x00\x00\x00\x00\x00\x17\x00\x00\x00\x00\x00\x00\x03www\x07example\x03com\x00", m.encode, issue29
end
end

0 comments on commit 4ffac87

Please sign in to comment.