[erlang-bugs] TXT record decoding bug in inet_dns

Geoff Cant <>
Mon Oct 6 16:19:20 CEST 2008

Hi there, while sneakily using the private inet_res API to do
interesting DNS queries, I discovered a long-standing bug in inet_dns.

inet_dns incorrectly decodes the RData for TXT records as RData instead
of [Length | Text] = RData, Text. (The RData for TXT records is encoded
as <<Len:8, Text:Len/binary>>).

Attached is a patch against R12B-4 to correct this bug. It should apply
with patch -p1 from the OTP sources root.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dns_txt_record_fix.diff
Type: text/x-patch
Size: 663 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20081006/b535fd3a/attachment.bin>
-------------- next part --------------

The second patch fixes the encoding of TXT records in the same way.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dns_txt_record_fix2.diff
Type: text/x-patch
Size: 668 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20081006/b535fd3a/attachment-0001.bin>
-------------- next part --------------

On a related note, I've found the functionality in inet_res to be
particularly useful and would like to know if the OTP team would
consider exposing and this functionality. This could be done as a new
'dns' modules for queries, resolution, encoding and decoding or perhaps
just exporting and documenting some of these private inet_res, inet_dns functions.

Ideally I would like to be able to do:

dns:lookup(Name, Type) -> {error, Error} | {ok, RR}.
dns:lookup(Server, Name, Type)
dns:lookup(Server, Name, Type, Timeout)

For at least the SOA, NS, TXT, A, CName, PTR, SRV and MX resource record

I'd be happy to write patches or a new dns module if the OTP team would
look favourably on including it in OTP.

Geoff Cant

More information about the erlang-bugs mailing list