From 928e84498fcf8f516fd6e628a0fd67e791842c8e Mon Sep 17 00:00:00 2001 From: Kurt Kartaltepe Date: Tue, 17 Aug 2021 20:39:17 -0700 Subject: [PATCH] wg-quick: linux: use sed for splitting config lines Bash's longest matching operators combined with extended globs is extremely slow for very large lines. There are probably very few people for which this is noticable but in a file with 800 AllowIPs on a single line it keeps wg-quick from stalling for 5s when performing operations. --- src/wg-quick/linux.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wg-quick/linux.bash b/src/wg-quick/linux.bash index e4d4c4f0..1babdd61 100755 --- a/src/wg-quick/linux.bash +++ b/src/wg-quick/linux.bash @@ -49,8 +49,8 @@ parse_options() { shopt -s nocasematch while read -r line || [[ -n $line ]]; do stripped="${line%%\#*}" - key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}" - value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}" + key=$(sed -e 's/=.*$//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "$stripped") + value=$(sed -e 's/^[^=]*=//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "$stripped") [[ $key == "["* ]] && interface_section=0 [[ $key == "[Interface]" ]] && interface_section=1 if [[ $interface_section -eq 1 ]]; then