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) 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
?DEBUG("client data: ~p~n", [Data]), error -> {State, false};
case catch url_decode_q_split(Path) of {NewState, Data} ->
{'EXIT', _} -> {NewState, false}; ?DEBUG("client data: ~p~n", [Data]),
{NPath, _Query} -> case catch url_decode_q_split(Path) of
LPath = normalize_path([NPE {'EXIT', _} -> {NewState, false};
|| NPE <- str:tokens(path_decode(NPath), <<"/">>)]), {NPath, _Query} ->
LQuery = case catch parse_urlencoded(Data) of LPath = normalize_path([NPE
{'EXIT', _Reason} -> []; || NPE <- str:tokens(path_decode(NPath), <<"/">>)]),
LQ -> LQ LQuery = case catch parse_urlencoded(Data) of
end, {'EXIT', _Reason} -> [];
{NewState, {LPath, LQuery, Data}} LQ -> LQ
end,
{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),