Fix logic error and mind the sub shell (fd)

This commit is contained in:
Dirk
2025-07-18 20:17:12 +02:00
parent 9e29b35e9e
commit 0d63a56c80

View File

@ -1938,10 +1938,12 @@ http_head_printf() {
IFS=/ read -r proto foo node query <<< "$1" IFS=/ read -r proto foo node query <<< "$1"
node=${node%:*} node=${node%:*}
# $node works here good as it connects via IPv6 first, then IPv4 # $node works here good as it connects via IPv6 first, then IPv4.
bash -c "exec 33<>/dev/tcp/$node/80" 2>/dev/null & # This is a subshell, so fd 8 is not inherited
bash -c "exec 8<>/dev/tcp/$node/80" 2>/dev/null &
wait_kill $! $HEADER_MAXSLEEP wait_kill $! $HEADER_MAXSLEEP
if [[ $? -ne 0 ]]; then if [[ $? -eq 0 ]]; then
exec 33<>/dev/tcp/$node/80
# not killed --> socket open. Now we connect to the virtual host "$node" # not killed --> socket open. Now we connect to the virtual host "$node"
printf -- "%b" "HEAD ${proto}//${node}/${query} HTTP/1.1\r\nUser-Agent: ${useragent}\r\nHost: ${node}\r\n${request_header}\r\nAccept: */*\r\n\r\n\r\n" >&33 2>$errfile printf -- "%b" "HEAD ${proto}//${node}/${query} HTTP/1.1\r\nUser-Agent: ${useragent}\r\nHost: ${node}\r\n${request_header}\r\nAccept: */*\r\n\r\n\r\n" >&33 2>$errfile
ret=0 ret=0