Skip to content

Commit 928e844

Browse files
committed
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.
1 parent b3aafa6 commit 928e844

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/wg-quick/linux.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ parse_options() {
4949
shopt -s nocasematch
5050
while read -r line || [[ -n $line ]]; do
5151
stripped="${line%%\#*}"
52-
key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
53-
value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
52+
key=$(sed -e 's/=.*$//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "$stripped")
53+
value=$(sed -e 's/^[^=]*=//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "$stripped")
5454
[[ $key == "["* ]] && interface_section=0
5555
[[ $key == "[Interface]" ]] && interface_section=1
5656
if [[ $interface_section -eq 1 ]]; then

0 commit comments

Comments
 (0)