From 2d74fa618f3a34a5487f5de37c4f6e2870b58273 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Wed, 15 Mar 2017 22:33:17 +0100 Subject: Fix handling of message length errors Message length errors in incoming messages were misinterpreted with transport_opt() {length_errors, exit} due to the throw introduced in commit 2ffb288: the corresponding catch in incoming/2 caught errors thrown by close/1, leading to failure when the error reason was interpreted as a diameter_packet record. Do away with the throw, that also caused woe in the parent commit. --- lib/diameter/src/base/diameter_peer_fsm.erl | 42 +++++++++++++---------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/lib/diameter/src/base/diameter_peer_fsm.erl b/lib/diameter/src/base/diameter_peer_fsm.erl index 7ee1e5fe59..d394156367 100644 --- a/lib/diameter/src/base/diameter_peer_fsm.erl +++ b/lib/diameter/src/base/diameter_peer_fsm.erl @@ -444,7 +444,8 @@ transition({connection_timeout, _}, _) -> %% Incoming message from the transport. transition({diameter, {recv, MsgT}}, S) -> - incoming(MsgT, S); + {Msg, NPid} = msg(MsgT), + incoming(recv(Msg, S), NPid, S); %% Timeout when still in the same state ... transition({timeout = T, PS}, #state{state = PS}) -> @@ -609,31 +610,26 @@ encode(Rec, Dict) -> diameter_codec:encode(Dict, #diameter_packet{header = Hdr, msg = Rec}). -%% incoming/2 +%% incoming/3 -incoming({Msg, NPid}, S) -> - try recv(Msg, S) of - T -> - NPid ! {diameter, discard}, - T - catch - {?MODULE, Name, Pkt} -> - incoming(Name, Pkt, NPid, S) - end; +incoming({recv, Name, Pkt}, NPid, #state{parent = Pid} = S) -> + Pid ! {recv, self(), get_route(Pkt), Name, Pkt, NPid}, + rcv(Name, Pkt, S); -incoming(Msg, S) -> - try - recv(Msg, S) - catch - {?MODULE, Name, Pkt} -> - incoming(Name, Pkt, false, S) - end. +incoming(T, false, _) -> + T; -%% incoming/4 +incoming(T, NPid, _) -> + NPid ! {diameter, discard}, + T. -incoming(Name, Pkt, NPid, #state{parent = Pid} = S) -> - Pid ! {recv, self(), get_route(Pkt), Name, Pkt, NPid}, - rcv(Name, Pkt, S). +%% msg/1 + +msg({_,_} = T) -> + T; + +msg(Msg) -> + {Msg, false}. %% recv/2 @@ -701,7 +697,7 @@ recv1('DPA' = N, %% Any other message with a header and no length errors: send to the %% parent. recv1(Name, Pkt, #state{}) -> - throw({?MODULE, Name, Pkt}). + {recv, Name, Pkt}. %% recv/3 -- cgit v1.2.3