From 3e39d7fd46e06aef18d2d1bb65876fbe31866a22 Mon Sep 17 00:00:00 2001 From: Andreas Schultz Date: Fri, 16 Aug 2024 12:36:50 +0200 Subject: [PATCH] handle PPP opts with broken sub-options encoding Protocol options are optional and 3GPP TS 29.060 says that optional, invalid IEs should be silently ignored. Do just that. --- src/gtp_packet.erl | 7 ++++++- test/gtp_SUITE.erl | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/gtp_packet.erl b/src/gtp_packet.erl index fe9d41d..0f8d155 100644 --- a/src/gtp_packet.erl +++ b/src/gtp_packet.erl @@ -444,7 +444,10 @@ decode_protocol_opts(<>, Protoc Opt = decode_protocol_ppp_opt(Id, Data), decode_protocol_opts(Next, Protocol, [Opt | Opts]); decode_protocol_opts(<>, 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 || <> <= Array]. @@ -801,6 +804,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, <>); encode_protocol_opts(Protocol, [{Id, Data} | T], Opts) when Id < 16#8000; Id >= 16#FF00 -> encode_protocol_opts(Protocol, T, <>); diff --git a/test/gtp_SUITE.erl b/test/gtp_SUITE.erl index 62395dd..0af1b9f 100644 --- a/test/gtp_SUITE.erl +++ b/test/gtp_SUITE.erl @@ -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")},