]> granicus.if.org Git - ejabberd/commitdiff
ejabberd_http: Handle missing POST data gracefully
authorHolger Weiss <holger@zedat.fu-berlin.de>
Tue, 27 Sep 2016 21:22:30 +0000 (23:22 +0200)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Tue, 27 Sep 2016 21:22:30 +0000 (23:22 +0200)
Return a "bad request" error instead of crashing if receiving POST/PUT
data fails.

src/ejabberd_http.erl

index 31f80be788e9e2cb99dbf00aca81d2c54d8f6ac8..e6e49d9b2380ff6dd3d33e1dadd05b6cbbddd202 100644 (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),