mirror of
https://repo.or.cz/socat.git
synced 2024-12-22 23:42:34 +00:00
dont leave UDP-LISTEN socket open after reject
This commit is contained in:
parent
a1c0e96592
commit
e142c3da6b
4 changed files with 61 additions and 3 deletions
4
CHANGES
4
CHANGES
|
@ -1,5 +1,9 @@
|
|||
|
||||
corrections:
|
||||
when UDP-LISTEN continued to listen after packet dropped by, e.g.,
|
||||
range option, the old listen socket would not be closed but a new one
|
||||
created. open sockets could accumulate.
|
||||
|
||||
there was a bug in ip*-recv with bind option: it did not bind, and
|
||||
with the first received packet an error occurred:
|
||||
socket_init(): unknown address family 0
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
"1.6.0.1+ip4bind+recvfromfork+x64+execstderr+execspaces+cosmetics+poll"
|
||||
"1.6.0.1+ip4bind+recvfromfork+x64+execstderr+execspaces+cosmetics+poll+udplistencont"
|
||||
|
|
57
test.sh
57
test.sh
|
@ -8032,9 +8032,9 @@ else
|
|||
numOK=$((numOK+1))
|
||||
fi
|
||||
kill $pid1 2>/dev/null
|
||||
wait ;;
|
||||
wait
|
||||
PORT="$_PORT" ;;
|
||||
esac
|
||||
PORT="$_PORT"
|
||||
N=$((N+1))
|
||||
|
||||
|
||||
|
@ -8317,6 +8317,59 @@ esac
|
|||
N=$((N+1))
|
||||
|
||||
|
||||
# a bug was found in the way UDP-LISTEN handles the listening socket:
|
||||
# when UDP-LISTEN continued to listen after a packet had been dropped by, e.g.,
|
||||
# range option, the old listen socket would not be closed but a new one created.
|
||||
NAME=UDP4LISTENCONT
|
||||
case "$TESTS" in
|
||||
*%functions%*|*%bugs%*|*%ip4%*|*%udp%*|*%$NAME%*)
|
||||
TEST="$NAME: let range drop a packet and see if old socket is closed"
|
||||
# idea: run a UDP4-LISTEN process with range option. Send it one packet from an
|
||||
# address outside range and check if two listening sockets are open then
|
||||
tf="$td/test$N.stdout"
|
||||
te="$td/test$N.stderr"
|
||||
tdiff="$td/test$N.diff"
|
||||
while [ "$(netstat -an |grep "^udp.*127.0.0.1:$PORT" |wc -l)" -ne 0 ]; do
|
||||
PORT=$((PORT+1))
|
||||
done
|
||||
tp=$PORT
|
||||
da1="test$N $(date) $RANDOM"
|
||||
a1="$LOCALHOST"
|
||||
a2="$SECONDADDR"
|
||||
#CMD0="$SOCAT $opts UDP4-LISTEN:$tp,bind=$a1,range=$a2/32 PIPE"
|
||||
CMD0="$SOCAT $opts UDP4-LISTEN:$tp,range=$a2/32 PIPE"
|
||||
CMD1="$SOCAT $opts - UDP-CONNECT:$a1:$tp"
|
||||
printf "test $F_n $TEST... " $N
|
||||
$CMD0 >/dev/null 2>"${te}0" &
|
||||
pid1=$!
|
||||
waitudp4port $tp 1
|
||||
echo "$da1" |$CMD1 >"${tf}1" 2>"${te}1" # this should fail
|
||||
rc1=$?
|
||||
waitudp4port $tp 1
|
||||
nsocks="$(netstat -an |grep "^udp.*[:.]$PORT" |wc -l)"
|
||||
kill $pid1 2>/dev/null; wait
|
||||
if [ $rc1 -ne 0 ]; then
|
||||
$PRINTF "$NO_RESULT\n"
|
||||
numCANT=$((numCANT+1))
|
||||
elif [ $nsocks -eq 0 ]; then
|
||||
$PRINTF "$NO_RESULT\n"
|
||||
numCANT=$((numCANT+1))
|
||||
elif [ $nsocks -ne 1 ]; then
|
||||
$PRINTF "$FAILED ($nsocks listening sockets)\n"
|
||||
echo "$CMD0 &"
|
||||
echo "$CMD1"
|
||||
cat "${te}0" "${te}1"
|
||||
numFAIL=$((numFAIL+1))
|
||||
else
|
||||
$PRINTF "$OK\n"
|
||||
if [ -n "$debug" ]; then cat "${te}0" "${te}1" "${te}2"; fi
|
||||
numOK=$((numOK+1))
|
||||
fi ;;
|
||||
esac
|
||||
PORT=$((PORT+1))
|
||||
N=$((N+1))
|
||||
|
||||
|
||||
echo "summary: $((N-1)) tests; $numOK ok, $numFAIL failed, $numCANT could not be performed"
|
||||
|
||||
if [ "$numFAIL" -gt 0 ]; then
|
||||
|
|
|
@ -231,6 +231,7 @@ int xioopen_ipdgram_listen(int argc, const char *argv[], struct opt *opts,
|
|||
/* drop packet */
|
||||
char buff[512];
|
||||
Recv(fd->stream.fd, buff, sizeof(buff), 0);
|
||||
Close(fd->stream.fd);
|
||||
continue;
|
||||
}
|
||||
Info1("permitting UDP connection from %s",
|
||||
|
|
Loading…
Reference in a new issue