diff --git a/lib/ssh/src/ssh_message.erl b/lib/ssh/src/ssh_message.erl index 65f3c21..8cf18b1 100644 --- a/lib/ssh/src/ssh_message.erl +++ b/lib/ssh/src/ssh_message.erl @@ -24,6 +24,7 @@ -module(ssh_message). -include_lib("public_key/include/public_key.hrl"). +-include_lib("kernel/include/logger.hrl"). -include("ssh.hrl"). -include("ssh_connect.hrl"). @@ -51,6 +52,7 @@ -define(Ename_list(X), ?STRING(ssh_bits:name_list(X)) ). -define(Empint(X), (ssh_bits:mpint(X))/binary ). -define(Ebinary(X), ?STRING(X) ). +-define(ALG_NAME_LIMIT, 64). ucl(B) -> try unicode:characters_to_list(B) of @@ -591,8 +593,22 @@ decode_kex_init(<>, Acc, 0) -> X = 0, list_to_tuple(lists:reverse([X, erl_boolean(Bool) | Acc])); decode_kex_init(<>, Acc, N) -> - Names = string:tokens(?unicode_list(Data), ","), - decode_kex_init(Rest, [Names | Acc], N -1). + BinParts = binary:split(Data, <<$,>>, [global]), + Process = + fun(<<>>, PAcc) -> + PAcc; + (Part, PAcc) -> + case byte_size(Part) > ?ALG_NAME_LIMIT of + true -> + ?LOG_DEBUG("Ignoring too long name", []), + PAcc; + false -> + Name = binary:bin_to_list(Part), + [Name | PAcc] + end + end, + Names = lists:foldr(Process, [], BinParts), + decode_kex_init(Rest, [Names | Acc], N - 1). %%%================================================================