mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-08-30 18:33:55 +02:00
Three ways the bounds added here failed to do their job: - get_first_free_port ended the scan cap with 'exit 1', but every caller runs it in a command substitution, so only the subshell died. The port variable came back empty, the next $((port + 1)) evaluated to 1, and the run limped on to a confusing wait_for_readyFile failure. Forcing the cap on ocsp-stapling.test: before, the script ran on and hung until an outer timeout killed it; now it exits 1 at the error. Return instead, and check the status at all 25 call sites across the six scripts. - The macOS timeout shim was a shell function. Backgrounding a function forks a subshell, so $! was the subshell and cleanup killed that while the server it was meant to stop leaked. Use a prefix variable that expands to nothing when timeout(1) is absent, keeping $! the real pid. - timeout -s KILL exits 137, not 124. Sites that read $? and treat any non-zero as 'feature not compiled in' turned a hang into exit 0, so the bound made a hang less visible than before. Add timed_out() and check it before those skip branches; use it for the version probes too, which matched any status >= 124.
180 lines
4.6 KiB
Bash
Executable File
180 lines
4.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# timeout(1) is GNU coreutils and absent on macOS; where it's missing, run the
|
|
# command unbounded (the flaky hang this guards against is Linux-only CI).
|
|
# A prefix variable rather than a shell function: backgrounding a function
|
|
# makes $! the forked subshell, so a later "kill $server_pid" would stop the
|
|
# wrapper and orphan the server it was meant to kill.
|
|
if command -v timeout >/dev/null 2>&1; then
|
|
TIMEOUT_KILL_2M="timeout -s KILL 2m"
|
|
else
|
|
TIMEOUT_KILL_2M=""
|
|
fi
|
|
|
|
|
|
#resume.test
|
|
|
|
# if we can, isolate the network namespace to eliminate port collisions.
|
|
if [[ -n "$NETWORK_UNSHARE_HELPER" ]]; then
|
|
if [[ -z "$NETWORK_UNSHARE_HELPER_CALLED" ]]; then
|
|
export NETWORK_UNSHARE_HELPER_CALLED=yes
|
|
exec "$NETWORK_UNSHARE_HELPER" "$0" "$@" || exit $?
|
|
fi
|
|
elif [ "${AM_BWRAPPED-}" != "yes" ]; then
|
|
bwrap_path="$(command -v bwrap)"
|
|
if [ -n "$bwrap_path" ]; then
|
|
export AM_BWRAPPED=yes
|
|
exec "$bwrap_path" --unshare-net --dev-bind / / "$0" "$@"
|
|
fi
|
|
unset AM_BWRAPPED
|
|
fi
|
|
|
|
# need a unique resume port since may run the same time as testsuite
|
|
# use server port zero hack to get one
|
|
resume_string="reused"
|
|
resume_sup_string="Resume session"
|
|
ems_string="Extended\ Master\ Secret"
|
|
resume_port=0
|
|
no_pid=-1
|
|
server_pid=$no_pid
|
|
counter=0
|
|
# let's use absolute path to a local dir (make distcheck may be in sub dir)
|
|
# also let's add some randomness by adding pid in case multiple 'make check's
|
|
# per source tree
|
|
ready_file=`pwd`/wolfssl_resume_ready$$
|
|
|
|
echo "ready file $ready_file"
|
|
|
|
remove_ready_file() {
|
|
if test -e "$ready_file"; then
|
|
echo -e "removing existing ready file"
|
|
rm "$ready_file"
|
|
fi
|
|
}
|
|
|
|
|
|
do_cleanup() {
|
|
echo "in cleanup"
|
|
|
|
if [ $server_pid != $no_pid ] && kill -0 $server_pid 2>&-
|
|
then
|
|
# sleep to give sanitizers time to dump backtraces.
|
|
sleep 1
|
|
echo "killing server"
|
|
kill -9 $server_pid
|
|
fi
|
|
remove_ready_file
|
|
}
|
|
|
|
do_trap() {
|
|
echo "got trap"
|
|
do_cleanup
|
|
exit 1
|
|
}
|
|
|
|
do_test() {
|
|
echo -e "\nStarting example server for resume test...\n"
|
|
|
|
#make sure we support session resumption (!NO_SESSION_CACHE)
|
|
# Check the client for the extended master secret disable option. If
|
|
# present we need to run the test twice.
|
|
options_check=`./examples/client/client '-?'`
|
|
case "$options_check" in
|
|
*$resume_sup_string*)
|
|
echo -e "\nResume test supported";;
|
|
*)
|
|
echo -e "\nResume test not supported with build"
|
|
return;;
|
|
esac
|
|
|
|
remove_ready_file
|
|
echo "./examples/server/server -r -R \"$ready_file\" -p $resume_port"
|
|
$TIMEOUT_KILL_2M ./examples/server/server -r -R "$ready_file" -p $resume_port &
|
|
server_pid=$!
|
|
|
|
counter=0
|
|
while [ ! -s "$ready_file" -a "$counter" -lt 20 ]; do
|
|
echo -e "waiting for ready file..."
|
|
sleep 0.1
|
|
counter=$((counter+ 1))
|
|
done
|
|
|
|
if test -e "$ready_file"; then
|
|
echo -e "found ready file, starting client..."
|
|
else
|
|
echo -e "NO ready file ending test..."
|
|
do_cleanup
|
|
exit 1
|
|
fi
|
|
|
|
# sleep for an additional 0.1 to mitigate race on write/read of $ready_file:
|
|
sleep 0.1
|
|
|
|
# get created port 0 ephemeral port
|
|
resume_port=`cat "$ready_file"`
|
|
|
|
echo "./examples/client/client $1 -r -p $resume_port"
|
|
capture_out=$(./examples/client/client $1 -r -p $resume_port 2>&1)
|
|
client_result=$?
|
|
|
|
if [ $client_result != 0 ]
|
|
then
|
|
echo -e "client failed!\ncapture_out=$capture_out\nclient_result=$client_result"
|
|
do_cleanup
|
|
exit 1
|
|
fi
|
|
|
|
wait $server_pid
|
|
server_result=$?
|
|
remove_ready_file
|
|
|
|
if [ $server_result != 0 ]
|
|
then
|
|
echo -e "client failed!"
|
|
exit 1
|
|
fi
|
|
|
|
case "$capture_out" in
|
|
*$resume_string*)
|
|
echo "resumed session" ;;
|
|
*)
|
|
echo "did NOT resume session as expected"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
trap do_trap INT TERM
|
|
|
|
./examples/client/client '-?' 2>&1 | grep -- 'Client not compiled in!'
|
|
if [ $? -ne 0 ]; then
|
|
./examples/server/server '-?' 2>&1 | grep -- 'Server not compiled in!'
|
|
if [ $? -ne 0 ]; then
|
|
RUN_TEST="Y"
|
|
fi
|
|
fi
|
|
|
|
./examples/client/client '-?' 2>&1 | grep -- 'Resume session'
|
|
if [ $? -ne 0 ]; then
|
|
RUN_TEST="Y"
|
|
fi
|
|
|
|
if [ "$RUN_TEST" = "Y" ]; then
|
|
do_test
|
|
|
|
# Check the client for the extended master secret disable option. If
|
|
# present we need to run the test twice.
|
|
options_check=`./examples/client/client -?`
|
|
case "$options_check" in
|
|
*$ems_string*)
|
|
echo -e "\nRepeating resume test without extended master secret..."
|
|
do_test -n ;;
|
|
*)
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
echo -e "\nSuccess!\n"
|
|
|
|
exit 0
|