From 280aa2f1b016118a9c3762bbad6066e8b369bed7 Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 2 Oct 2017 15:36:38 +0200 Subject: [PATCH] Fix crash in mod_http_fileserver when logging URL with query elements (#2021) --- src/mod_http_fileserver.erl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mod_http_fileserver.erl b/src/mod_http_fileserver.erl index 4e3cfd08b..c1c5b6461 100644 --- a/src/mod_http_fileserver.erl +++ b/src/mod_http_fileserver.erl @@ -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;