[erlang-bugs] Unexpected crash using inet_res:lookup/3

Daniel Luna daniel@REDACTED
Mon Mar 12 13:49:55 CET 2012


I still call bug on this.

1. I would expect an erlang function to fail with 'badarg' if given
bad arguments, not some random "I could not be bothered to code for
this case" crash further down the line
2. It only fails with a string with adjacent dots (or which starts
with a dot, something which is not in the documentation), but it *does
not* fail when given a binary, an atom, and a whole lot of other bad
arguments.

This to me does not follow the type specification.

/Daniel

On 12 March 2012 07:31, Gustav Simonsson
<gustav.simonsson@REDACTED> wrote:
>
> Actually if you look at the typespec:
>
> Name = dns_name() | inet:ip_address()
>
> dns_name() = string()
>
> A string with no adjacent dots.
>
> // Gustav Simonsson
>
> Sent from my PC
>
> ----- Original Message -----
>> From: "Daniel Luna" <daniel@REDACTED>
>> To: erlang-bugs@REDACTED
>> Sent: Friday, 9 March, 2012 9:55:46 PM
>> Subject: [erlang-bugs] Unexpected crash using inet_res:lookup/3
>>
>> Hi,
>>
>> inet_res:lookup/3 normally doesn't crash for almost any input (see
>> examples 7-10 where I feed atoms and binaries to it).
>>
>> But in the case of a string starting with period or a containing a
>> double period it will crash in inet_dns:encode_labels/4.
>>
>> No mention of this being expected in the documentation so assume that
>> it's a bug.  See examples below.
>>
>> Linux, R15B.
>>
>> Cheers,
>>
>> Daniel
>>
>>
>> Erlang R15B (erts-5.9) [source] [64-bit] [smp:5:5] [async-threads:0]
>> [kernel-poll:false]
>>
>> Eshell V5.9  (abort with ^G)
>> 1> inet_res:lookup("erlang.com", in, mx).
>> [{20,"mail.numbering.info"}]
>> 2> inet_res:lookup("erlang..com", in, mx).
>> ** exception error: no function clause matching
>> inet_dns:encode_labels(<<0,2,1,0,0,1,0,0,0,0,0,0,6,101,114,108,97,110,103>>,
>>
>> {1,{[<<"erlang">>,<<>>,<<"com">>],12,nil,nil}},
>>                                                                        19,
>>
>> [<<>>,<<"com">>]) (inet_dns.erl, line 693)
>>      in function  inet_dns:encode_name/4 (inet_dns.erl, line 674)
>>      in call from inet_dns:encode_query_section/3 (inet_dns.erl, line
>>      268)
>>      in call from inet_dns:encode/1 (inet_dns.erl, line 239)
>>      in call from inet_res:make_query/5 (inet_res.erl, line 669)
>>      in call from inet_res:make_query/4 (inet_res.erl, line 637)
>>      in call from inet_res:res_query/5 (inet_res.erl, line 608)
>>      in call from inet_res:resolve/5 (inet_res.erl, line 141)
>> 3> inet_res:lookup("..", in, mx).
>> ** exception error: no function clause matching
>> inet_dns:encode_labels(<<0,3,1,0,0,1,0,0,0,0,0,0>>,{0,nil},12,[<<>>,<<>>])
>> (inet_dns.erl, line 693)
>>      in function  inet_dns:encode_name/4 (inet_dns.erl, line 674)
>>      in call from inet_dns:encode_query_section/3 (inet_dns.erl, line
>>      268)
>>      in call from inet_dns:encode/1 (inet_dns.erl, line 239)
>>      in call from inet_res:make_query/5 (inet_res.erl, line 669)
>>      in call from inet_res:make_query/4 (inet_res.erl, line 637)
>>      in call from inet_res:res_query/5 (inet_res.erl, line 608)
>>      in call from inet_res:resolve/5 (inet_res.erl, line 141)
>> 4> inet_res:lookup(".", in, mx).
>> []
>> 5> inet_res:lookup(".com", in, mx).
>> ** exception error: no function clause matching
>> inet_dns:encode_labels(<<0,5,1,0,0,1,0,0,0,0,0,0>>,{0,nil},12,[<<>>,<<"com">>])
>> (inet_dns.erl, line 693)
>>      in function  inet_dns:encode_name/4 (inet_dns.erl, line 674)
>>      in call from inet_dns:encode_query_section/3 (inet_dns.erl, line
>>      268)
>>      in call from inet_dns:encode/1 (inet_dns.erl, line 239)
>>      in call from inet_res:make_query/5 (inet_res.erl, line 669)
>>      in call from inet_res:make_query/4 (inet_res.erl, line 637)
>>      in call from inet_res:res_query/5 (inet_res.erl, line 608)
>>      in call from inet_res:resolve/5 (inet_res.erl, line 141)
>> 6> inet_res:lookup("erlang.", in, mx).
>> []
>> 7> inet_res:lookup([1234567], in, mx).
>> []
>> 8> inet_res:lookup([atom], in, mx).
>> []
>> 9> inet_res:lookup(atom, in, mx).
>> []
>> 10> inet_res:lookup(<<"binary">>, in, mx).
>> []
>> _______________________________________________
>> erlang-bugs mailing list
>> erlang-bugs@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-bugs
>>
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs



More information about the erlang-bugs mailing list