diff --git a/include/dns_tests.hrl b/include/dns_tests.hrl index 6833de6..16192e7 100644 --- a/include/dns_tests.hrl +++ b/include/dns_tests.hrl @@ -54,6 +54,12 @@ message_edns_test() -> Bin = encode_message(Msg), ?assertEqual(Msg, decode_message(Bin)). +missing_additional_section_test() -> + %% Query for test./IN/A with missing additional section + Bin = <<192, 46, 0, 32, 0, 1, 0, 0, 0, 0, 0, 1, 4, 116, 101, 115, + 116, 0, 0, 1, 0, 1>>, + ?assertMatch({truncated, _, <<>>}, decode_message(Bin)). + tsig_no_tsig_test() -> MsgBin = encode_message(#dns_message{}), Name = <<"name">>, diff --git a/src/dns.erl b/src/dns.erl index e074d77..bf98c9f 100644 --- a/src/dns.erl +++ b/src/dns.erl @@ -217,10 +217,10 @@ decode_message_questions(DataBin, Count, MsgBin, Qs) -> decode_message_body(DataBin, Count, MsgBin) -> decode_message_body(DataBin, Count, MsgBin, []). -decode_message_body(<<>>, _Count, _MsgBin, RRs) -> - {lists:reverse(RRs), <<>>}; decode_message_body(DataBin, 0, _MsgBin, RRs) -> {lists:reverse(RRs), DataBin}; +decode_message_body(<<>>, _Count, _MsgBin, RRs) -> + {truncated, lists:reverse(RRs), <<>>}; decode_message_body(DataBin, Count, MsgBin, RRs) -> case catch decode_dname(DataBin, MsgBin) of {<<>>, <