From ad524a56b7f304c6982ce3c0b0708edbcf770657 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Mon, 12 Jan 2015 22:21:36 +0100 Subject: [PATCH] Passive addresses like TCP-LISTEN with empty port bound to random --- CHANGES | 4 ++++ test.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ xio-ip.c | 3 +++ 3 files changed, 51 insertions(+) diff --git a/CHANGES b/CHANGES index 263253f..3ef741b 100644 --- a/CHANGES +++ b/CHANGES @@ -33,6 +33,10 @@ corrections: e.g. an SSL connection which the parent assumed to still be active. Test: SYSTEM_SHUTDOWN + Passive (listening or receiving) addresses with empty port field bound + to a random port instead of terminating with error. + Test: TCP4_NOPORT + ####################### V 1.7.2.4: corrections: diff --git a/test.sh b/test.sh index f127900..1fd75db 100755 --- a/test.sh +++ b/test.sh @@ -11859,6 +11859,50 @@ PORT=$((PORT+1)) N=$((N+1)) +# test if TCP4-LISTEN with empty port arg terminates with error +NAME=TCP4_NOPORT +case "$TESTS" in +*%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%tcp%*|*%tcp4%*|*%$NAME%*) +TEST="$NAME: test if TCP4-LISTEN with empty port arg bails out" +# run socat with TCP4-LISTEN with empty port arg. Check if it terminates +# immediately with return code 1 +if ! eval $NUMCOND; then :; else +tf="$td/test$N.stdout" +te="$td/test$N.stderr" +t0rc="$td/test$N.rc" +tdiff="$td/test$N.diff" +da="test$N $(date) $RANDOM" +CMD0="$SOCAT $opts TCP4-LISTEN: /dev/null" +printf "test $F_n $TEST... " $N +{ $CMD0 >/dev/null 2>"${te}0"; echo $? >"$t0rc"; } & 2>/dev/null +pid0=$! +sleep 1 +kill $pid0 2>/dev/null; wait +if [ ! -f "$t0rc" ]; then + $PRINTF "$FAILED\n" + echo "$CMD0 &" + cat "${te}0" + echo "did not terminate with error" + numFAIL=$((numFAIL+1)) + listFAIL="$listFAIL $N" +elif ! echo 1 |diff - "$t0rc"; then + $PRINTF "$FAILED\n" + echo "$CMD0 &" + cat "${te}0" + echo "expected return code 1" + numFAIL=$((numFAIL+1)) + listFAIL="$listFAIL $N" +else + $PRINTF "$OK\n" + numOK=$((numOK+1)) +fi +fi # NUMCOND + ;; +esac +PORT=$((PORT+1)) +N=$((N+1)) + + ################################################################################## #================================================================================= # here come tests that might affect your systems integrity. Put normal tests diff --git a/xio-ip.c b/xio-ip.c index 271c8d7..bc870d2 100644 --- a/xio-ip.c +++ b/xio-ip.c @@ -149,6 +149,9 @@ int xiogetaddrinfo(const char *node, const char *service, memset(sau, 0, *socklen); sau->soa.sa_family = family; + if (service && service[0]=='\0') { + Error("empty port/service"); + } /* if service is numeric we don't want to have a lookup (might take long with NIS), so we handle this specially */ if (service && isdigit(service[0]&0xff)) {