Skip to content

Commit fef08ae

Browse files
committed
Merge branch 'michal/diameter/fix-crash-in-diameter-dist-when-avp-is-short/OTP-20243' into maint
* michal/diameter/fix-crash-in-diameter-dist-when-avp-is-short/OTP-20243: Fix crash in diameter_dist when Session-Id avp is shorter than 8 bytes
2 parents 7d2d2c9 + 003625a commit fef08ae

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

lib/diameter/src/base/diameter_dist.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ session_id(_, 0) -> %% give up
247247
false;
248248

249249
%% Session-Id = Command Code 263, V-bit = 0.
250-
session_id(<<263:32, 0:1, _:7, Len:24, _/binary>> = Bin, _) ->
250+
%% RFC 6733 4.2 (and RFC 3588 4.2) says that minimum avp length is 8.
251+
session_id(<<263:32, 0:1, _:7, Len:24, _/binary>> = Bin, _) when Len >= 8 ->
251252
case Bin of
252253
<<Avp:Len/binary, _/binary>> ->
253254
<<_:8/binary, Sid/binary>> = Avp,

lib/diameter/test/diameter_dist_SUITE.erl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040

4141
%% The test cases
4242
traffic/1,
43-
zero_length_avp_infinite_loop/1
43+
zero_length_avp_infinite_loop/1,
44+
short_length_avp_crash/1
4445
]).
4546

4647
%% diameter callbacks
@@ -117,7 +118,7 @@ suite() ->
117118
[{timetrap, {seconds, 90}}].
118119

119120
all() ->
120-
[traffic, zero_length_avp_infinite_loop].
121+
[traffic, zero_length_avp_infinite_loop, short_length_avp_crash].
121122

122123
init_per_suite(Config) ->
123124
?DUTIL:init_per_suite(Config).
@@ -149,6 +150,21 @@ zero_length_avp_infinite_loop(_Config) ->
149150

150151
discard = diameter_dist:route_session(Request, #{default => discard}).
151152

153+
short_length_avp_crash(_Config) ->
154+
MalformedMsg = <<1, 0, 0, 28, %% Version=1, Length=28
155+
128, 0, 0, 1, %% Flags=Request, Command=1
156+
0, 0, 0, 0, %% Application-Id=0
157+
0, 0, 0, 1, %% Hop-by-Hop=1
158+
0, 0, 0, 1, %% End-to-End=1
159+
0, 0, 1, 7, %% AVP Code=263 (Session-Id)
160+
0, %% Flags=0 (V-bit=0)
161+
0, 0, 4>>, %% AVP Length=4 (minimum is 8)
162+
RecvData = {recvdata, undefined, name, undefined, undefined, undefined, undefined},
163+
Pkt = #diameter_packet{bin = MalformedMsg},
164+
Request = {Pkt, undefined, undefined, undefined, undefined, RecvData},
165+
166+
discard = diameter_dist:route_session(Request, #{default => discard}).
167+
152168
%% ===========================================================================
153169

154170
%% run/0

0 commit comments

Comments
 (0)