From d3c2f7625c21439cf2579b4b4c43029459b27206 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 6 May 2024 12:09:56 +0200 Subject: [PATCH] mwan3: "use" action: run process via `exec` and handle whitespace Previously the "use" command had the following shortcomings: * a subprocess was created instead of replacing the shell process * whitespace in arguments was not handled correctly Implementation detail: In shell context the `"$@"` expression should be used (instead of `$*`). This allows the safe handling of arguments containing whitespace. Closes: #20001 Signed-off-by: Lars Kruse --- net/mwan3/files/usr/sbin/mwan3 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 index ea3d4c6a74..e884d22f6b 100755 --- a/net/mwan3/files/usr/sbin/mwan3 +++ b/net/mwan3/files/usr/sbin/mwan3 @@ -220,7 +220,6 @@ use() { # firewall rules local interface device src_ip family - mwan3_init interface=$1 ; shift [ -z "$*" ] && echo "no command specified for mwan3 use" && return @@ -234,16 +233,17 @@ use() { [ -z "$family" ] && echo "could not find family for $interface. Using ipv4." && family='ipv4' echo "Running '$*' with DEVICE=$device SRCIP=$src_ip FWMARK=$MMX_DEFAULT FAMILY=$family" - # shellcheck disable=SC2048 - FAMILY=$family DEVICE=$device SRCIP=$src_ip FWMARK=$MMX_DEFAULT LD_PRELOAD=/lib/mwan3/libwrap_mwan3_sockopt.so.1.0 $* - + # if a program (not a shell builtin) is run: use "exec" for allowing direct process control + if [ -x "$(command -v "$1")" ]; then + set -- exec "$@" + fi + FAMILY=$family DEVICE=$device SRCIP=$src_ip FWMARK=$MMX_DEFAULT LD_PRELOAD=/lib/mwan3/libwrap_mwan3_sockopt.so.1.0 "$@" } case "$1" in ifup|ifdown|interfaces|policies|connected|rules|status|start|stop|restart|use|internal) mwan3_init - # shellcheck disable=SC2048 - $* + "$@" ;; *) help -- 2.30.2