Skip to content

Commit ee05a86

Browse files
committed
Better handling of invalid percent encoded urls in ejabberd_http
1 parent 44fa357 commit ee05a86

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/ejabberd_http.erl

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,15 @@ extract_path_query(#state{request_method = Method,
395395
when Method =:= 'GET' orelse
396396
Method =:= 'HEAD' orelse
397397
Method =:= 'DELETE' orelse Method =:= 'OPTIONS' ->
398-
case catch url_decode_q_split_normalize(Path) of
399-
{'EXIT', Error} ->
400-
?DEBUG("Error decoding URL '~p': ~p", [Path, Error]),
401-
{State, false};
398+
try url_decode_q_split_normalize(Path) of
402399
{LPath, Query} ->
403-
LQuery = case catch parse_urlencoded(Query) of
404-
{'EXIT', _Reason} -> [];
405-
LQ -> LQ
400+
LQuery = try parse_urlencoded(Query)
401+
catch _:_ -> []
406402
end,
407403
{State, {LPath, LQuery, <<"">>, Path}}
404+
catch _:Error ->
405+
?DEBUG("Error decoding URL '~p': ~p", [Path, Error]),
406+
{State, false}
408407
end;
409408
extract_path_query(#state{request_method = Method,
410409
request_path = {abs_path, Path},
@@ -413,26 +412,25 @@ extract_path_query(#state{request_method = Method,
413412
sockmod = _SockMod,
414413
socket = _Socket} = State)
415414
when (Method =:= 'POST' orelse Method =:= 'PUT') andalso Len>0 ->
416-
case catch url_decode_q_split_normalize(Path) of
417-
{'EXIT', Error} ->
418-
?DEBUG("Error decoding URL '~p': ~p", [Path, Error]),
419-
{State, false};
415+
try url_decode_q_split_normalize(Path) of
420416
{LPath, _Query} ->
421417
case Method of
422418
'PUT' ->
423419
{State, {LPath, [], Trail, Path}};
424420
'POST' ->
425421
case recv_data(State) of
426422
{ok, Data} ->
427-
LQuery = case catch parse_urlencoded(Data) of
428-
{'EXIT', _Reason} -> [];
429-
LQ -> LQ
423+
LQuery = try parse_urlencoded(Data)
424+
catch _:_ -> []
430425
end,
431426
{State, {LPath, LQuery, Data, Path}};
432427
error ->
433428
{State, false}
434429
end
435430
end
431+
catch _:Error ->
432+
?DEBUG("Error decoding URL '~p': ~p", [Path, Error]),
433+
{State, false}
436434
end;
437435
extract_path_query(State) ->
438436
{State, false}.

0 commit comments

Comments
 (0)