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

Raimo Niskanen <>
Thu Oct 9 10:27:53 CEST 2008


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" <> writes:
> 
> > 2008/10/6 Geoff Cant <>:
> >> 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}.
>  

> 
> Cheers,
> -- 
> Geoff Cant

> _______________________________________________
> erlang-bugs mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-bugs

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-bugs mailing list