]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg-quick: match from beginning rather than shift right
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 6 Feb 2018 11:52:09 +0000 (12:52 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 6 Feb 2018 11:52:09 +0000 (12:52 +0100)
Before, this meant that it simply took the last 15 characters, instead
of erroring out when there's more than 15 chars.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/wg-quick.bash

index a028b982cd15860a13bf71ce4d646d7b854b5f75..80921bf07195141d481bd19a0dcb57186f32e792 100755 (executable)
@@ -31,10 +31,10 @@ parse_options() {
        CONFIG_FILE="$1"
        [[ $CONFIG_FILE =~ ^[a-zA-Z0-9_=+.-]{1,15}$ ]] && CONFIG_FILE="/etc/wireguard/$CONFIG_FILE.conf"
        [[ -e $CONFIG_FILE ]] || die "\`$CONFIG_FILE' does not exist"
-       [[ $CONFIG_FILE =~ /?([a-zA-Z0-9_=+.-]{1,15})\.conf$ ]] || die "The config file must be a valid interface name, followed by .conf"
+       [[ $CONFIG_FILE =~ (^|/)([a-zA-Z0-9_=+.-]{1,15})\.conf$ ]] || die "The config file must be a valid interface name, followed by .conf"
        CONFIG_FILE="$(readlink -f "$CONFIG_FILE")"
        ((($(stat -c '0%#a' "$CONFIG_FILE") & $(stat -c '0%#a' "${CONFIG_FILE%/*}") & 0007) == 0)) || echo "Warning: \`$CONFIG_FILE' is world accessible" >&2
-       INTERFACE="${BASH_REMATCH[1]}"
+       INTERFACE="${BASH_REMATCH[2]}"
        shopt -s nocasematch
        while read -r line || [[ -n $line ]]; do
                key="${line%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"