From 789c0254844c460f9a392bb5725e6819c36c21b3 Mon Sep 17 00:00:00 2001 From: Dirk Date: Wed, 30 Sep 2026 19:26:47 +0200 Subject: [PATCH] Fix starttls_io() in 3.2 As noted in #3154 there was an unused variable `waitsleep` in `starttls_io` which was filled with argument passed \#3. The loop search for the pattern in `$2` however was the filled with another variable `nr_waits` which was pre-set to 10 (`STARTTLS_SLEEP`) This PR for 3.2 fixes that by - removing STARTTLS_SLEEP from this function - passing a value of 4 to this function when called For ~1200 xmpp tests 2 was the maximum in less than 10% of the cases, so 4 should be really safe. `starttls_postgres_dialog()` uses also `starttls_io` but it should be a safe bet when searching for the pattern `S` --- testssl.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/testssl.sh b/testssl.sh index 77d0bcc..059d950 100755 --- a/testssl.sh +++ b/testssl.sh @@ -11669,13 +11669,14 @@ run_alpn() { # arg1: send string # arg2: success string: an egrep pattern -# arg3: number of loops we should read from the buffer (optional, otherwise STARTTLS_SLEEP) +# arg3: number of loops we should read from the buffer. As of 2026 we were good with max 2, see #3154 +# To be safe we're using 4 in calling starttls_io() to look for the pattern in $2 +# starttls_io() { - local nr_waits=$STARTTLS_SLEEP + local nr_waits=$3 local buffer="" local -i i - [[ -n "$3" ]] && waitsleep=$3 [[ -z "$2" ]] && echo "FIXME $((LINENO))" # If there's a sending part it's IO. Postgres sends via socket and replies via @@ -11696,7 +11697,7 @@ starttls_io() { for ((i=1; i < nr_waits; i++ )); do [[ "$DEBUG" -ge 2 ]] && echo -en "\nS: " && echo $buffer if [[ "$buffer" =~ $2 ]]; then - debugme echo " ---> reply matched \"$2\"" + debugme echo " ---> reply # $i matched \"$2\"" # the fd sometimes still seem to contain chars which confuses the following TLS handshake, trying to empty: # dd of=/dev/null bs=512 count=1 <&5 2>/dev/null return 0 @@ -11912,9 +11913,9 @@ starttls_xmpp_dialog() { namespace="jabber:client" [[ "$STARTTLS_PROTOCOL" == xmpp-server ]] && namespace="jabber:server" - starttls_io "" 'starttls(.*)features' 1 && - starttls_io "" '" 'JUSTSEND' 2 + starttls_io "" 'starttls(.*)features' 4 && + starttls_io "" '" 'JUSTSEND' 4 ret=$? debugme echo "=== finished xmpp STARTTLS dialog with ${ret} ===" return $ret @@ -11939,7 +11940,7 @@ starttls_postgres_dialog() { debugme echo "=== starting postgres STARTTLS dialog ===" socksend "${starttls_init}" 0 && debugme echo "${debugpad}initiated STARTTLS" && - starttls_io "" S 1 && debugme echo "${debugpad}received ack (=\"S\") for STARTTLS" + starttls_io "" S 4 && debugme echo "${debugpad}received ack (=\"S\") for STARTTLS" ret=$? debugme echo "=== finished postgres STARTTLS dialog with ${ret} ===" return $ret