From 2a291dfd275551e79432a5e0e8728ec1c6fb785e Mon Sep 17 00:00:00 2001 From: Andrew Mayorov Date: Tue, 10 Oct 2023 12:31:19 +0700 Subject: [PATCH] fix(audit): handle abstract forms when logging `eval_erl` --- apps/emqx_ctl/src/emqx_ctl.erl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/emqx_ctl/src/emqx_ctl.erl b/apps/emqx_ctl/src/emqx_ctl.erl index ed6aa7bb1..8f6b3309b 100644 --- a/apps/emqx_ctl/src/emqx_ctl.erl +++ b/apps/emqx_ctl/src/emqx_ctl.erl @@ -331,14 +331,13 @@ safe_to_existing_atom(Str) -> is_initialized() -> ets:info(?CMD_TAB) =/= undefined. -audit_log(Level, From, Log = #{args := Args}) -> +audit_log(Level, From, Log) -> case lookup_command(audit) of {error, _} -> ignore; {ok, {Mod, Fun}} -> try - Log1 = Log#{args => [unicode:characters_to_binary(A) || A <- Args]}, - apply(Mod, Fun, [Level, From, Log1]) + apply(Mod, Fun, [Level, From, normalize_audit_log_args(Log)]) catch _:Reason:Stacktrace -> ?LOG_ERROR(#{ @@ -349,12 +348,18 @@ audit_log(Level, From, Log = #{args := Args}) -> end end. --define(TOO_SLOW, 3000). - audit_level(ok, _Duration) -> info; audit_level({ok, _}, _Duration) -> info; audit_level(_, _) -> error. +normalize_audit_log_args(Log = #{args := [Parsed | _] = Exprs, cmd := eval_erl}) when + is_tuple(Parsed) +-> + String = erl_pp:exprs(Exprs, [{linewidth, 10000}]), + Log#{args => [unicode:characters_to_binary(String)]}; +normalize_audit_log_args(Log = #{args := Args}) -> + Log#{args => [unicode:characters_to_binary(A) || A <- Args]}. + eval_erl([Parsed | _] = Expr) when is_tuple(Parsed) -> eval_expr(Expr); eval_erl([String]) ->