Skip to content

Commit ac85724

Browse files
committed
Do not compress domain name in SRV RDATA
[RFC2782] prohibits use of name compression for the target host name in the RDATA of a SRV record. [RFC2782]: https://datatracker.ietf.org/doc/rfc2782/ Closes: #29
1 parent 0c10845 commit ac85724

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/resolv.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,14 +1487,14 @@ def put_string_list(ds)
14871487
}
14881488
end
14891489

1490-
def put_name(d)
1491-
put_labels(d.to_a)
1490+
def put_name(d, compress: true)
1491+
put_labels(d.to_a, compress: compress)
14921492
end
14931493

1494-
def put_labels(d)
1494+
def put_labels(d, compress: true)
14951495
d.each_index {|i|
14961496
domain = d[i..-1]
1497-
if idx = @names[domain]
1497+
if compress && idx = @names[domain]
14981498
self.put_pack("n", 0xc000 | idx)
14991499
return
15001500
else
@@ -2328,7 +2328,7 @@ def encode_rdata(msg) # :nodoc:
23282328
msg.put_pack("n", @priority)
23292329
msg.put_pack("n", @weight)
23302330
msg.put_pack("n", @port)
2331-
msg.put_name(@target)
2331+
msg.put_name(@target, compress: false)
23322332
end
23332333

23342334
def self.decode_rdata(msg) # :nodoc:

test/resolv/test_resource.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ def test_hash
2323
def test_coord
2424
Resolv::LOC::Coord.create('1 2 1.1 N')
2525
end
26+
27+
def test_srv_no_compress
28+
# Domain name in SRV RDATA should not be compressed
29+
issue29 = 'https://github.com/ruby/resolv/issues/29'
30+
m = Resolv::DNS::Message.new(0)
31+
m.add_answer('example.com', 0, Resolv::DNS::Resource::IN::SRV.new(0, 0, 0, 'www.example.com'))
32+
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
33+
end
2634
end

0 commit comments

Comments
 (0)