]> granicus.if.org Git - ejabberd/commitdiff
Fix crash in mod_http_fileserver when logging URL with query elements (#2021)
authorBadlop <badlop@process-one.net>
Mon, 2 Oct 2017 13:36:38 +0000 (15:36 +0200)
committerBadlop <badlop@process-one.net>
Mon, 2 Oct 2017 13:36:38 +0000 (15:36 +0200)
src/mod_http_fileserver.erl

index 4e3cfd08b9c3d6483154687ce61c08cb5f82bd2d..c1c5b6461bc6884b8e8993841f5068b88494f737 100644 (file)
@@ -424,8 +424,7 @@ add_to_log(File, FileSize, Code, Request) ->
     {{Year, Month, Day}, {Hour, Minute, Second}} = calendar:local_time(),
     IP = ip_to_string(element(1, Request#request.ip)),
     Path = join(Request#request.path, "/"),
-    Query = case join(lists:map(fun(E) -> lists:concat([element(1, E), "=", binary_to_list(element(2, E))]) end,
-                               Request#request.q), "&") of
+    Query = case stringify_query(Request#request.q) of
                [] ->
                    "";
                String ->
@@ -445,6 +444,13 @@ add_to_log(File, FileSize, Code, Request) ->
              [IP, Day, Month, Year, Hour, Minute, Second, Request#request.method, Path, Query, Code,
                FileSize, Referer, UserAgent]).
 
+stringify_query(Q) ->
+    join(
+       lists:map(fun(E) ->
+               lists:concat([binary_to_list(element(1, E)), "=", binary_to_list(element(2, E))])
+           end, Q),
+       "&").
+
 find_header(Header, Headers, Default) ->
     case lists:keysearch(Header, 1, Headers) of
       {value, {_, Value}} -> Value;