From 54f6ef62cdc15de2fa8b9cb7e7c31aeff38fa2aa Mon Sep 17 00:00:00 2001 From: Chris Wells Date: Sat, 28 Nov 2020 23:22:17 -0500 Subject: [PATCH] Properly escape config property and value. --- usr/local/share/bastille/config.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/config.sh b/usr/local/share/bastille/config.sh index b40835b5..0203c6b6 100644 --- a/usr/local/share/bastille/config.sh +++ b/usr/local/share/bastille/config.sh @@ -71,7 +71,8 @@ for _jail in ${JAILS}; do continue fi - MATCH_LINE=$(grep "^\s*${PROPERTY}[ =;]" "${FILE}" 2>/dev/null) + ESCAPED_PROPERTY=$(echo "${PROPERTY}" | sed 's/\./\\\./g') + MATCH_LINE=$(grep "^ *${ESCAPED_PROPERTY}[ =;]" "${FILE}" 2>/dev/null) MATCH_FOUND=$? if [ "${ACTION}" = 'get' ]; then @@ -89,6 +90,7 @@ for _jail in ${JAILS}; do fi else # Setting the value. -- cwells if [ -n "${VALUE}" ]; then + VALUE=$(echo "${VALUE}" | sed 's/\//\\\//g') if echo "${VALUE}" | grep ' ' > /dev/null 2>&1; then # Contains a space, so wrap in quotes. -- cwells VALUE="'${VALUE}'" fi @@ -100,7 +102,7 @@ for _jail in ${JAILS}; do if [ $MATCH_FOUND -ne 0 ]; then # No match, so insert the property at the end. -- cwells echo "$(awk -v line="${LINE}" '$0 == "}" { print line; } 1 { print $0; }' "${FILE}")" > "${FILE}" else # Replace the existing value. -- cwells - sed -i '' -E "s/ *${PROPERTY}[ =;].*/${LINE}/" "${FILE}" + sed -i '' -E "s/ *${ESCAPED_PROPERTY}[ =;].*/${LINE}/" "${FILE}" fi fi done