From 1a4be26afca8133c6d3d2ed4c4d6bdea460bf3f7 Mon Sep 17 00:00:00 2001 From: Dirk Date: Thu, 22 May 2025 19:55:36 +0200 Subject: [PATCH] Change for Linux to builtin printf This suggested PR changes the order of which printf is being used in `choose_printf()` so that Linux uses not /usr/bin/printf . This is for some checks slightly faster. Also PRINTF is now a tunable parameter which can be set through the enviroment like PRINTF=/usr/bin/printf ./testssl.sh It doesn't / shouldn't solve the bug #2783. But it might help to reproduce it. --- testssl.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/testssl.sh b/testssl.sh index 18c6cd5..8aceb7c 100755 --- a/testssl.sh +++ b/testssl.sh @@ -241,7 +241,7 @@ SSL_RENEG_WAIT=${SSL_RENEG_WAIT:-0.25} # time between SSL Renegotiation checks LC_COLLATE="" # ensures certain regex patterns work as expected and aren't localized, see setup_lc_collate() HAS_LOCALE=false SYSTEM2="" # currently only being used for WSL = bash on windows -PRINTF="" # which external printf to use. Empty presets the internal one, see #1130 +PRINTF="${PRINTF:-''}" # which external printf to use. Empty presets the internal one, see #1130 CIPHERS_BY_STRENGTH_FILE="" TLS_DATA_FILE="" # mandatory file for socket-based handshakes OPENSSL="" # ~/bin/openssl.$(uname).$(uname -m) if you run this from GitHub. Linux otherwise probably /usr/bin/openssl @@ -21091,19 +21091,26 @@ setup_lc_collate() { choose_printf() { local p ptf + # external supplied PRINTF overrides everything + [[ -n "$PRINTF" ]] && [[ -x "$PRINTF" ]] && return 0 + + # This now (2025) works under Linux and saves time as opposed to /usr/bin/printf. + # This worked on MacOS also before + if type -t printf | grep -q builtin; then + if printf "\xc0\x14\x00\xc0\xff\xee" | hexdump -C | grep -q 'c0 14 00 c0 ff ee'; then + PRINTF="" + return 0 + fi + fi ptf="$(type -aP printf)" if [[ -n "$ptf" ]]; then for p in $ptf; do - if $p "\xc0\x14\xc0\xff\xee" | hexdump -C | grep -q 'c0 14 c0 ff ee'; then + if $p "\xc0\x14\x00\xc0\xff\xee" | hexdump -C | grep -q 'c0 14 00 c0 ff ee'; then PRINTF=$p return 0 fi done fi - if type -t printf >/dev/null; then - PRINTF="" - return 0 - fi fatal "Neither external printf nor shell internal found. " $ERR_CLUELESS }