Skip to content

Commit

Permalink
handle PPP opts with broken sub-options encoding
Browse files Browse the repository at this point in the history
Protocol options are optional and 3GPP TS 29.060 says that optional,
invalid IEs should be silently ignored. Do just that.

(cherry picked from commit 3e39d7f)
  • Loading branch information
RoadRunnr committed Sep 2, 2024
1 parent 306f265 commit ea1c857
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/gtp_packet.erl
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ decode_protocol_opts(<<Id:16, Length:8, Data:Length/bytes, Next/binary>>, Protoc
Opt = decode_protocol_ppp_opt(Id, Data),
decode_protocol_opts(Next, Protocol, [Opt | Opts]);
decode_protocol_opts(<<Id:16, Length:8, Data:Length/bytes, Next/binary>>, Protocol, Opts) ->
decode_protocol_opts(Next, Protocol, [{Id, Data} | Opts]).
decode_protocol_opts(Next, Protocol, [{Id, Data} | Opts]);
decode_protocol_opts(<<_Id:16, Length:8, Data/binary>> = Raw, Protocol, Opts)
when Length > byte_size(Data) ->
decode_protocol_opts(<<>>, Protocol, [{raw, Raw} | Opts]).

decode_array_of_seq_no(Array) ->
[X || <<X:16/integer>> <= Array].
Expand Down Expand Up @@ -769,6 +772,8 @@ encode_protocol_config_opts({Protocol, Opts}) ->

encode_protocol_opts(_Protocol, [], Opts) ->
Opts;
encode_protocol_opts(Protocol, [{raw, Raw} | T], Opts) ->
encode_protocol_opts(Protocol, T, <<Opts/binary, Raw/binary>>);
encode_protocol_opts(Protocol, [{Id, Data} | T], Opts)
when Id < 16#8000; Id >= 16#FF00 ->
encode_protocol_opts(Protocol, T, <<Opts/binary, Id:16, (size(Data)):8, Data/binary>>);
Expand Down
8 changes: 8 additions & 0 deletions test/gtp_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ test_messages() ->
"00850004ac1410a8850004ac1410a9870004000b921f")},
{{v1, pco_rel97},
hexstr2bin("3215000A0003A8F4696E0000018084000100")},
{{v1, broken_protocol_opts},
hexstr2bin("3210009e000000009c3d00000225053590694975f40337f020fffeff0eb20ffc"
"1003591521110359151f1405800002f12183000403746e3184001d80c0230601"
"000006000080c7d7566a4e82b050d1cee3780ed5431c000085000442c9bffe85"
"000442c9bffe860008915689051092544787000f0213921f7396fefe742affff"
"008e0094000160970001019800080137f0204e30409a99000269009a00085389"
"758054936010")},

{{v2, echo_request},
hexstr2bin("40010009006a50000300010073")},

Expand Down

0 comments on commit ea1c857

Please sign in to comment.