fix: newline validation bug in entrypoint.sh

echo adds trailing newline, causing false positives. Use printf and case statement instead.
This commit is contained in:
NW
2026-06-24 12:09:32 +01:00
parent 67c1436670
commit 45d2bfbcf8

View File

@@ -4,14 +4,13 @@ set -e
validate_alnum() {
local val="$1"
local name="$2"
if ! echo "$val" | grep -qE '^[a-zA-Z0-9._-]+$'; then
case "$val" in
*$'\n'*) echo "ERROR: $name contains newlines"; exit 1 ;;
esac
if ! printf '%s' "$val" | grep -qE '^[a-zA-Z0-9._-]+$'; then
echo "ERROR: $name contains invalid characters: $val"
exit 1
fi
if echo "$val" | grep -q $'\n'; then
echo "ERROR: $name contains newlines: $val"
exit 1
fi
}
validate_alnum "$SSH_HOST_IP" "SSH_HOST_IP"