Skip to contentSkip to conversation

wg-quick: escaped # in Pre/PostUp/Down recognised

PATCH In review Robyn Kosching 2 participants 2 messages May 21, 2025 – May 23, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wg-quick: escaped # in Pre/PostUp/Down recognised

Hi there,

currently commands in pre/PostUp/Down options in wireguard configs are stripped of everything starting with the first # - even if the # is escaped or in a string.

This patch leaves command interpretation in Pre/PostUp/Down options to bash as it can already interpret comments and escaped #.

---
 src/wg-quick/linux.bash | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
src/wg-quick/linux.bash +5 -4
index 4193ce5..50bb794 100755
@@ -51,6 +51,7 @@ parse_options() {
 		stripped="${line%%\#*}"
 		key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
 		value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
+		commandvalue="${line#*=}"; commandvalue="${commandvalue##*([[:space:]])}"; commandvalue="${commandvalue%%*([[:space:]])}"
 		[[ $key == "["* ]] && interface_section=0
 		[[ $key == "[Interface]" ]] && interface_section=1
 		if [[ $interface_section -eq 1 ]]; then
@@ -61,10 +62,10 @@ parse_options() {
 				[[ $v =~ (^[0-9.]+$)|(^.*:.*$) ]] && DNS+=( $v ) || DNS_SEARCH+=( $v )
 			done; continue ;;
 			Table) TABLE="$value"; continue ;;
-			PreUp) PRE_UP+=( "$value" ); continue ;;
-			PreDown) PRE_DOWN+=( "$value" ); continue ;;
-			PostUp) POST_UP+=( "$value" ); continue ;;
-			PostDown) POST_DOWN+=( "$value" ); continue ;;
+			PreUp) PRE_UP+=( "$commandvalue" ); continue ;;
+			PreDown) PRE_DOWN+=( "$commandvalue" ); continue ;;
+			PostUp) POST_UP+=( "$commandvalue" ); continue ;;
+			PostDown) POST_DOWN+=( "$commandvalue" ); continue ;;
 			SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;;
 			esac
 		fi

base-commit: 13f4ac4cb74b5a833fa7f825ba785b1e5774e84f

Signature · 1 line
2.34.1