From c90dd2ce88eb29bfe7330483f5d1569191496a1d Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Wed, 1 Apr 2015 14:43:37 +0200 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 82e8957..e14c57b 100644 --- a/CHANGES +++ b/CHANGES @@ -176,6 +176,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 + porting: Red Hat issue 1020203: configure checks fail with some compilers. Use case: clang diff --git a/test.sh b/test.sh index c5724c3..c37fce8 100755 --- a/test.sh +++ b/test.sh @@ -12243,6 +12243,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 "no return code of CMD0 stored" >&2 + echo "$CMD0 &" + cat "${te}0" + numFAIL=$((numFAIL+1)) + listFAIL="$listFAIL $N" +elif ! echo 1 |diff - "$t0rc" >"$tdiff"; then + $PRINTF "$FAILED\n" + echo "CMD0 exited with $(cat $t0rc), expected 1" + echo "$CMD0 &" + cat "${te}0" + 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 # before this paragraph. 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)) {