From 34367fc4ec08d599b62f0b194603c3e81a88bdb0 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Wed, 27 Sep 2023 23:06:14 +0200 Subject: [PATCH] fix(audit_log): pretty print shell args --- apps/emqx_machine/src/emqx_restricted_shell.erl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/emqx_machine/src/emqx_restricted_shell.erl b/apps/emqx_machine/src/emqx_restricted_shell.erl index ea6d7d7ab..115fa478f 100644 --- a/apps/emqx_machine/src/emqx_restricted_shell.erl +++ b/apps/emqx_machine/src/emqx_restricted_shell.erl @@ -104,7 +104,7 @@ max_heap_size_warning(MF, Args) -> msg => "shell_process_exceed_max_heap_size", current_heap_size => HeapSize, function => MF, - args => Args, + args => pp_args(Args), max_heap_size => ?MAX_HEAP_SIZE }) end. @@ -115,21 +115,30 @@ log(IsAllow, MF, Args) -> ?AUDIT(warning, "from_remote_console", #{ time => logger:timestamp(), function => MF, - args => Args, + args => pp_args(Args), permission => IsAllow }), to_console(IsAllow, MF, Args). to_console(prohibited, MF, Args) -> warning("DANGEROUS FUNCTION: FORBIDDEN IN SHELL!!!!!", []), - ?SLOG(error, #{msg => "execute_function_in_shell_prohibited", function => MF, args => Args}); + ?SLOG(error, #{ + msg => "execute_function_in_shell_prohibited", + function => MF, + args => pp_args(Args) + }); to_console(exempted, MF, Args) -> limit_warning(MF, Args), ?SLOG(error, #{ - msg => "execute_dangerous_function_in_shell_exempted", function => MF, args => Args + msg => "execute_dangerous_function_in_shell_exempted", + function => MF, + args => pp_args(Args) }); to_console(ok, MF, Args) -> limit_warning(MF, Args). warning(Format, Args) -> io:format(?RED_BG ++ Format ++ ?RESET ++ "~n", Args). + +pp_args(Args) -> + iolist_to_binary(io_lib:format("~0p", [Args])).