Skip to content

Commit 89d93b1

Browse files
committed
Add guards for undefined ClientIn
This can happen in sasl2 when initial-response is not provided.
1 parent f96c9ad commit 89d93b1

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

src/xmpp_sasl_digest.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ mech_step(#state{step = 5, auth_module = AuthModule,
132132
mech_step(_, _) ->
133133
{error, unexpected_response}.
134134

135-
parse(S) -> parse1(binary_to_list(S), "", []).
135+
parse(S) when is_binary(S) -> parse1(binary_to_list(S), "", []);
136+
parse(_) -> bad.
136137

137138
parse1([$= | Cs], S, Ts) ->
138139
parse2(Cs, lists:reverse(S), "", Ts);

src/xmpp_sasl_fast.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ mech_step(State, ClientIn) ->
101101
{error, parser_failed}
102102
end.
103103

104-
-spec prepare(binary()) -> {binary(), binary()} | error.
105-
prepare(ClientIn) ->
104+
-spec prepare(term()) -> {binary(), binary()} | error.
105+
prepare(ClientIn) when is_binary(ClientIn) ->
106106
case parse(ClientIn) of
107107
[User, Hash] ->
108108
case parse_authzid(User) of
@@ -113,7 +113,8 @@ prepare(ClientIn) ->
113113
end;
114114
_ ->
115115
error
116-
end.
116+
end;
117+
prepare(_) -> error.
117118

118119
-spec parse(binary()) -> [binary()].
119120
parse(S) ->

src/xmpp_sasl_plain.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ mech_step(State, ClientIn) ->
5555
{error, parser_failed}
5656
end.
5757

58-
-spec prepare(binary()) -> {binary(), binary(), binary()} | error.
59-
prepare(ClientIn) ->
58+
-spec prepare(term()) -> {binary(), binary(), binary()} | error.
59+
prepare(ClientIn) when is_binary(ClientIn) ->
6060
case parse(ClientIn) of
6161
[<<"">>, UserMaybeDomain, Password] ->
6262
case parse_authzid(UserMaybeDomain) of
@@ -74,7 +74,8 @@ prepare(ClientIn) ->
7474
end;
7575
_ ->
7676
error
77-
end.
77+
end;
78+
prepare(_) -> error.
7879

7980
-spec parse(binary()) -> [binary()].
8081
parse(S) ->

src/xmpp_sasl_scram.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ mech_new(Mech, ChannelBindings, Mechs, _UAId, _Host, #{get_password := GetPasswo
105105
#state{step = 2, get_password = GetPassword, algo = Algo,
106106
channel_bindings = CB, ssdp = Ssdp}.
107107

108+
mech_step(_State, ClientIn) when not is_binary(ClientIn) ->
109+
{error, parser_failed};
108110
mech_step(#state{step = 2, algo = Algo, ssdp = Ssdp} = State, ClientIn) ->
109111
case re:split(ClientIn, <<",">>, [{return, binary}]) of
110112
[CBind, _AuthorizationIdentity, UserNameAttribute, ClientNonceAttribute | Extensions] ->

0 commit comments

Comments
 (0)