From 1431ba6fbec9095160677d932d6ce7b76d92ded6 Mon Sep 17 00:00:00 2001 From: "Michael T. DeGuzis" Date: Tue, 16 Aug 2022 08:57:39 -0400 Subject: [PATCH] Use bash subshell for procfs interpolation of cmdline file --- save_command_strategies/linux_procfs.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/save_command_strategies/linux_procfs.sh b/save_command_strategies/linux_procfs.sh index ff8231f..6b64f7e 100755 --- a/save_command_strategies/linux_procfs.sh +++ b/save_command_strategies/linux_procfs.sh @@ -13,7 +13,10 @@ exit_safely_if_empty_ppid() { full_command() { [[ -z "$COMMAND_PID" ]] && exit 0 - cat /proc/${COMMAND_PID}/cmdline | xargs -0 printf "%q " + # See: https://unix.stackexchange.com/a/567021 + # Avoid complications with system printf by using bash subshell interpolation. + # This will properly escape sequences and null in cmdline. + cat /proc/${COMMAND_PID}/cmdline | xargs -0 bash -c 'printf "%q " "$0" "$@"' } main() {