24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-18 22:15:20 +02: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,7 +396,9 @@ extract_path_query(#state{request_method = Method,
socket = _Socket} = State) socket = _Socket} = State)
when (Method =:= 'POST' orelse Method =:= 'PUT') andalso when (Method =:= 'POST' orelse Method =:= 'PUT') andalso
is_integer(Len) -> is_integer(Len) ->
{NewState, Data} = recv_data(State, Len), case recv_data(State, Len) of
error -> {State, false};
{NewState, Data} ->
?DEBUG("client data: ~p~n", [Data]), ?DEBUG("client data: ~p~n", [Data]),
case catch url_decode_q_split(Path) of case catch url_decode_q_split(Path) of
{'EXIT', _} -> {NewState, false}; {'EXIT', _} -> {NewState, false};
@ -408,6 +410,7 @@ extract_path_query(#state{request_method = Method,
LQ -> LQ LQ -> LQ
end, end,
{NewState, {LPath, LQuery, Data}} {NewState, {LPath, LQuery, Data}}
end
end; end;
extract_path_query(State) -> extract_path_query(State) ->
{State, false}. {State, false}.
@ -525,7 +528,7 @@ recv_data(State, Len, Acc) ->
recv_data(State, Len - byte_size(Data), <<Acc/binary, Data/binary>>); recv_data(State, Len - byte_size(Data), <<Acc/binary, Data/binary>>);
Err -> Err ->
?DEBUG("Cannot receive HTTP data: ~p", [Err]), ?DEBUG("Cannot receive HTTP data: ~p", [Err]),
<<"">> error
end; end;
_ -> _ ->
Trail = (State#state.trail), Trail = (State#state.trail),