Permalink
Browse files

make sure to always send proper strings to file:write() while logging

Failure to send proper string to file:write() on FreeBSD could result in a
emulator Bad value on output port 'efile' if bad data makes it there, say
an atom.
  • Loading branch information...
1 parent c90a997 commit 8904c51b30b971965411d30b4b11da57418afd20 @nicad nicad committed with vinoski Jun 14, 2012
Showing with 5 additions and 2 deletions.
  1. +5 −2 src/yaws_log.erl
View
@@ -316,7 +316,7 @@ handle_cast({_ServerName, access, Fd, {Ip, Req, InH, OutH, _}}, State) ->
Msg = fmt_access_log(State#state.now, fmt_ip(Ip, State), User,
[Meth, $\s, Path, $\s, Ver],
Status, Len, Referer, UserAgent),
- file:write(Fd, Msg),
+ file:write(Fd, safe_log_data(Msg)),
{noreply, State};
false ->
{noreply, State}
@@ -334,7 +334,7 @@ handle_cast({ServerName, auth, Fd, {Ip, Path, Item}}, State) ->
{401, Realm} -> [" 401 realm=", Realm];
{401, User, PWD} -> [" 401 user=", User, " badpwd=", PWD]
end, "\n"],
- file:write(Fd, Msg),
+ file:write(Fd, safe_log_data(Msg)),
{noreply, State};
false ->
{noreply,State}
@@ -489,5 +489,8 @@ left_fill(N, Width, _Fill) when length(N) >= Width ->
left_fill(N, Width, Fill) ->
left_fill([Fill|N], Width, Fill).
+safe_log_data(Elements) ->
+ [ yaws:to_string(E) || E <- Elements ].
+

0 comments on commit 8904c51

Please sign in to comment.