From 83c2a412ab23ea9e88e7abbf633fc116a82ea872 Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Mon, 22 Aug 2011 16:58:42 -0500 Subject: [PATCH] Mash in the remainder of adt-error-format-protection branch --- src/error_logger_lager_h.erl | 6 +++--- src/lager_crash_log.erl | 2 +- test/lager_test_backend.erl | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index 41141e6..5983bdb 100644 --- a/src/error_logger_lager_h.erl +++ b/src/error_logger_lager_h.erl @@ -80,7 +80,7 @@ handle_event(Event, State) -> [ID, Name, format_reason(Reason)]); _ -> ?CRASH_LOG(Event), - ?LOG(error, Pid, lager_trunc_io:format(Fmt, Args, 4096)) + ?LOG(error, Pid, lager:safe_format(Fmt, Args, 4096)) end; {error_report, _GL, {Pid, std_error, D}} -> ?CRASH_LOG(Event), @@ -100,11 +100,11 @@ handle_event(Event, State) -> ?CRASH_LOG(Event), ?LOG(error, Pid, ["CRASH REPORT ", format_crash_report(Self, Neighbours)]); {warning_msg, _GL, {Pid, Fmt, Args}} -> - ?LOG(warning, Pid, lager_trunc_io:format(Fmt, Args, 4096)); + ?LOG(warning, Pid, lager:safe_format(Fmt, Args, 4096)); {warning_report, _GL, {Pid, std_warning, Report}} -> ?LOG(warning, Pid, print_silly_list(Report)); {info_msg, _GL, {Pid, Fmt, Args}} -> - ?LOG(info, Pid, lager_trunc_io:format(Fmt, Args, 4096)); + ?LOG(info, Pid, lager:safe_format(Fmt, Args, 4096)); {info_report, _GL, {Pid, std_info, D}} when is_list(D) -> Details = lists:sort(D), case Details of diff --git a/src/lager_crash_log.erl b/src/lager_crash_log.erl index 81e553d..af673ce 100644 --- a/src/lager_crash_log.erl +++ b/src/lager_crash_log.erl @@ -166,7 +166,7 @@ schedule_rotation(Date) -> %% to limit the formatted string's size. limited_fmt(Fmt, Args, FmtMaxBytes) -> - lager_trunc_io:format(Fmt, Args, FmtMaxBytes). + lager:safe_format(Fmt, Args, FmtMaxBytes). limited_str(Term, FmtMaxBytes) -> {Str, _} = lager_trunc_io:print(Term, FmtMaxBytes), diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index 77c1d75..9e638af 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -647,6 +647,12 @@ error_logger_redirect_test_() -> ] }. +safe_format_test() -> + ?assertEqual("foo bar", lists:flatten(lager:safe_format("~p ~p", [foo, bar], 1024))), + ?assertEqual("FORMAT ERROR: \"~p ~p ~p\" [foo,bar]", lists:flatten(lager:safe_format("~p ~p ~p", [foo, bar], 1024))), + ?assertEqual("FORMAT ERROR: \"~s\" [1]", lists:flatten(lager:safe_format("~s", [1], 1024))), + ok. + -endif.