Skip to content

Commit

Permalink
normalize FQDNs by lowercaseing them in all IEs
Browse files Browse the repository at this point in the history
  • Loading branch information
RoadRunnr committed Jun 2, 2021
1 parent b7206ad commit 0bfdad3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/gtp_packet.erl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ decode_v2_msg(<<TEI:32/integer, SeqNo:24, _Spare1:8, IEs/binary>>, 1, Type) ->
decode_v2_msg(<<SeqNo:24, _Spare1:8, IEs/binary>>, 0, Type) ->
#gtp{version = v2, type = message_type_v2(Type), tei = undefined, seq_no = SeqNo, ie = IEs}.

%% only intended for domain names, no support for anything outside
%% of the allowed character range
to_lower_char(C) when C >= $A andalso C =< $Z ->
C bor 16#20;
to_lower_char(C) -> C.

to_lower(BinStr) when is_binary(BinStr) ->
<< << (to_lower_char(C)) >> || << C >> <= BinStr >>.

%%%===================================================================
%%% Internal functions
%%%===================================================================
Expand Down Expand Up @@ -379,7 +388,7 @@ decode_v1_uli(<<Type:8, MCCMNC:3/bytes, LAC:16, Info:16, _/binary>>, Instance) -
end.

decode_fqdn(FQDN) ->
[ Part || <<Len:8, Part:Len/bytes>> <= FQDN ].
[ to_lower(Part) || <<Len:8, Part:Len/bytes>> <= FQDN ].

decode_isdn_address_string(<<>>) ->
{isdn_address, 1, 1, 1, <<"000000000000000">>};
Expand Down
2 changes: 1 addition & 1 deletion test/property_test/gtplib_prop.erl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ dns_label() ->
?LET(I, int_range(1,64),
vector(I,
oneof(
lists:seq($A, $Z) ++ lists:seq($a, $z) ++ lists:seq($0, $9) ++ [$-]))).
lists:seq($a, $z) ++ lists:seq($0, $9) ++ [$-]))).

dns_name_list() ->
?SUCHTHAT(N,
Expand Down

0 comments on commit 0bfdad3

Please sign in to comment.