[erlang-bugs] : : TXT record decoding bug in inet_dns

Raimo Niskanen raimo+erlang-bugs@REDACTED
Fri Feb 27 12:47:37 CET 2009


On Fri, Feb 27, 2009 at 01:54:08AM +0100, Geoff Cant wrote:
> 
> Hi there, I noticed this patch didn't make it into R12B5 - any chance of
> it making R13?

Well it stumbled on the finish line, but I have already
applied it to the dev version of R13A. In the process
I corrected for SPF records too; I attach that patch.

> 
> I've updated the OTP git repository here
> (http://github.com/mfoemmel/erlang-otp/tree/dns_fix). I think the patch
> still applies cleanly.
> 
> Cheers,
> --Geoff
> 
> Raimo Niskanen <raimo+erlang-bugs@REDACTED> writes:
> 
> > Thank you for your patch.
> >
> > We will take a look at it and if it does not break
> > anything it will most probably be accepted.
> >
> >
> >
> > On Tue, Oct 07, 2008 at 02:28:06PM +0200, Geoff Cant wrote:
> >> "Matthew Dempsky" <matthew.dempsky@REDACTED> writes:
> >> 
> >> > 2008/10/6 Geoff Cant <nem@REDACTED>:
> >> >> 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>>).
> >> >
> >> > RDATA for TXT records allows more than one character string.
> >> 
> >> Good point - in which case txt records should decode to a list of
> >> strings. Updated patch attached (encoding and decoding) against R12B-4
> >> (supercedes previous patches).
> >> 
> >
> >> diff --git a/lib/kernel/src/inet_dns.erl b/lib/kernel/src/inet_dns.erl
> >> index b99b774..6bd7867 100644
> >> --- a/lib/kernel/src/inet_dns.erl
> >> +++ b/lib/kernel/src/inet_dns.erl
> >> @@ -400,11 +400,20 @@ decode_data(?S_MX, _, [P1,P0 | Dom], Buffer) ->
> >>      { ?i16(P1,P0), decode_domain(Dom, Buffer) };
> >>  decode_data(?S_SRV, _, [P1,P0, W1,W0, Po1,Po0 | Dom], Buffer) ->
> >>      { ?i16(P1,P0), ?i16(W1,W0), ?i16(Po1,Po0), decode_domain(Dom, Buffer) };
> >> -decode_data(?S_TXT, _, Data, _Buffer) -> Data;
> >> +decode_data(?S_TXT, _, Data, _Buffer) ->
> >> +    decode_txt(Data);
> >>  %% sofar unknown or non standard
> >>  decode_data(_, _, Data, _Buffer) ->
> >>      Data.
> >>  
> >> +decode_txt_data(List) ->
> >> +    decode_txt_data(List, []).
> >> +
> >> +decode_txt_data([], Acc) -> Acc;
> >> +decode_txt_data([Len | Data], Acc) ->
> >> +    {Str,Rest} = lists:split(Len, Data),
> >> +    decode_txt(Rest, Acc ++ [Str]).
> >> +
> >>  decode_domain(Data, Buffer) ->
> >>      case dn_expand(Data, Buffer) of
> >>  	error -> error;
> >> @@ -498,7 +507,8 @@ encode_data(?S_MX, in, {Pref, Exch}, Ptrs, L) ->
> >>  encode_data(?S_SRV, in, {Prio, Weight, Port, Target}, Ptrs, L) ->
> >>      {EDom, NPtrs} = dn_compress(Target, Ptrs, [], L),
> >>      {?int16(Prio) ++ ?int16(Weight) ++ ?int16(Port) ++ EDom, NPtrs};
> >> -encode_data(?S_TXT, in, Data, Ptrs, _)     -> {Data, Ptrs};
> >> +encode_data(?S_TXT, in, Data, Ptrs, _)     ->
> >> +    {[[length(Str) | Str] || Str <- Data], Ptrs};
> >>  %% sofar unknown or non standard
> >>  encode_data(_, _, Data, Ptrs, _)        -> {Data, Ptrs}.
> >>  

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inet_dns.diff
Type: text/x-patch
Size: 3441 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20090227/21e03c18/attachment.bin>


More information about the erlang-bugs mailing list