25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

ejabberd_http: Handle missing POST data gracefully

Return a "bad request" error instead of crashing if receiving POST/PUT
data fails.
This commit is contained in:
Holger Weiss 2016-09-27 23:22:30 +02:00
parent acab2270f1
commit d4b4f35a0e

View File

@ -396,18 +396,21 @@ extract_path_query(#state{request_method = Method,
socket = _Socket} = State)
when (Method =:= 'POST' orelse Method =:= 'PUT') andalso
is_integer(Len) ->
{NewState, Data} = recv_data(State, Len),
?DEBUG("client data: ~p~n", [Data]),
case catch url_decode_q_split(Path) of
{'EXIT', _} -> {NewState, false};
{NPath, _Query} ->
LPath = normalize_path([NPE
|| NPE <- str:tokens(path_decode(NPath), <<"/">>)]),
LQuery = case catch parse_urlencoded(Data) of
{'EXIT', _Reason} -> [];
LQ -> LQ
end,
{NewState, {LPath, LQuery, Data}}
case recv_data(State, Len) of
error -> {State, false};
{NewState, Data} ->
?DEBUG("client data: ~p~n", [Data]),
case catch url_decode_q_split(Path) of
{'EXIT', _} -> {NewState, false};
{NPath, _Query} ->
LPath = normalize_path([NPE
|| NPE <- str:tokens(path_decode(NPath), <<"/">>)]),
LQuery = case catch parse_urlencoded(Data) of
{'EXIT', _Reason} -> [];
LQ -> LQ
end,
{NewState, {LPath, LQuery, Data}}
end
end;
extract_path_query(State) ->
{State, false}.
@ -525,7 +528,7 @@ recv_data(State, Len, Acc) ->
recv_data(State, Len - byte_size(Data), <<Acc/binary, Data/binary>>);
Err ->
?DEBUG("Cannot receive HTTP data: ~p", [Err]),
<<"">>
error
end;
_ ->
Trail = (State#state.trail),