From 8c488b7655b924066930b57b4a0d2ff8be4296b6 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sun, 8 Jan 2023 10:36:00 +0100 Subject: debvm-waitssh: error out if port number is not a positive integer --- debvm-waitssh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/debvm-waitssh b/debvm-waitssh index bde1a93..a35c783 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -142,6 +142,19 @@ case "$1" in ;; esac +# Guard against strings containing anything but digits, strings starting with +# zero and empty strings as the port number. +# +# We cannot use [!0-9] because that matches on any character (or possibly +# multi-character collation element) that sorts in between 0 and 9. +case "$PORT" in *[!0123456789]*|0?*|""|??????*) + if [ "$VERBOSITY" -ge 1 ]; then + echo "$0: port '$PORT' is not a positive integer between 1 and 99999" >&2 + fi + exit 1 + ;; +esac + now=$(date +%s) deadline=$((now + TOTALTIMEOUT)) while test "$now" -lt "$deadline"; do -- cgit v1.2.3