From c8e96611f141dd14ba0a6e8924e2951852401d8e Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Fri, 22 Mar 2013 12:03:52 +0100 Subject: Fix escaping unfortunate strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Strings that look like arguments, as well as no string at all, were causing trouble. Reported by: Thomas Bächler --- src/netctl | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/netctl b/src/netctl index 9e14e55..c8703c6 100755 --- a/src/netctl +++ b/src/netctl @@ -29,9 +29,9 @@ END sd_escape() { local IFS='' # Prevent a recursion loop on backspaces - set "${@//\\/\\x5c}" + set -- "${@//\\/\\x5c}" while [[ "$*" =~ [^[:alnum:].:_/\\] ]]; do - set "${@//$BASH_REMATCH/$(printf '\\x%x' "'$BASH_REMATCH")}" + set -- "${@//$BASH_REMATCH/$(printf '\\x%x' "'$BASH_REMATCH")}" done printf '%s\n' "${@//\//-}" } @@ -40,7 +40,7 @@ sd_escape() { sd_call() { local command=$1 shift - set $(sd_escape "$@") + set -- $(sd_escape "$@") systemctl $command $(printf 'netctl@%s.service\n' "$@") } @@ -109,11 +109,12 @@ unit_enable() { echo ".include /usr/lib/systemd/system/netctl@.service" > "$unit" echo -e "\n[Unit]" >> "$unit" [[ -n $Description ]] && echo "Description=$Description" >> "$unit" - : ${BindsToInterfaces=$Interface} - printf 'BindsTo=sys-subsystem-net-devices-%s.device\n' \ - $(sd_escape "${BindsToInterfaces[@]}") >> "$unit" - printf 'After=sys-subsystem-net-devices-%s.device\n' \ - $(sd_escape "${BindsToInterfaces[@]}") >> "$unit" + if [[ -n ${BindsToInterfaces=$Interface} ]]; then + printf 'BindsTo=sys-subsystem-net-devices-%s.device\n' \ + $(sd_escape "${BindsToInterfaces[@]}") >> "$unit" + printf 'After=sys-subsystem-net-devices-%s.device\n' \ + $(sd_escape "${BindsToInterfaces[@]}") >> "$unit" + fi if [[ -n $After ]]; then printf 'After="netctl@%s.service"\n' \ $(sd_escape "${After[@]}") >> "$unit" -- cgit v1.2.3-24-g4f1b