From 1a1cbb1598e17382dc569781dd4ca2ddc9868bdc Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Tue, 26 Oct 2021 18:41:55 +0200 Subject: [PATCH] Option -R did not only dump right-to-left, but also left-to-right traffic --- CHANGES | 5 +++++ socat.c | 4 ++-- test.sh | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index f31cd51..8866ccf 100644 --- a/CHANGES +++ b/CHANGES @@ -35,6 +35,11 @@ Corrections: Test: ABSTRACT_USER Thanks to Andreas Fink for reporting this issue. + Option -R did not only dump ("sniff") right-to-left, but also + left-to-right traffic to the given file. + Test: SNIFF_RIGHT_TO_LEFT + Thanks to 1314 gsf for reporting this bug and sending a patch. + Testing: Prevent the TIMESTAMP tests from sporadically failing due do seconds overflow diff --git a/socat.c b/socat.c index b619a3d..8c9b841 100644 --- a/socat.c +++ b/socat.c @@ -208,7 +208,7 @@ int main(int argc, const char *argv[]) { O_LARGEFILE| #endif O_NONBLOCK, 0664)) < 0) - Error2("option -r \"%s\": %s", a, strerror(errno)); + Error2("option -R \"%s\": %s", a, strerror(errno)); break; case 'b': if (arg1[0][2]) { a = *arg1+2; @@ -1303,7 +1303,7 @@ int xiotransfer(xiofile_t *inpipe, xiofile_t *outpipe, if (!righttoleft && socat_opts.sniffleft >= 0) { Write(socat_opts.sniffleft, buff, bytes); - } else if (socat_opts.sniffright >= 0) { + } else if (righttoleft && socat_opts.sniffright >= 0) { Write(socat_opts.sniffright, buff, bytes); } diff --git a/test.sh b/test.sh index 492470e..9fd3f34 100755 --- a/test.sh +++ b/test.sh @@ -15112,7 +15112,7 @@ kill -9 $pid 2>/dev/null; rc=$? # did process still exist? if [ $rc -ne 0 ]; then $PRINTF "$OK\n" - if [" $VERBOSE" ]; then + if [ "$VERBOSE" ]; then echo "$CMD &" >&2 fi numOK=$((numOK+1)) @@ -15173,6 +15173,50 @@ PORT=$((PORT+1)) N=$((N+1)) +# Test if option -R does not "sniff" left-to-right traffic +NAME=SNIFF_RIGHT_TO_LEFT +case "$TESTS" in +*%$N%*|*%functions%*|*%bugs%*|*%$NAME%*) +TEST="$NAME: test if option -R does not "sniff" left-to-right traffic" +# Use option -R, check if left-to-right traffic is not in output file +if ! eval $NUMCOND; then :; else +tf="$td/test$N.stdout" +te="$td/test$N.stderr" +ts="$td/test$N.sniffed" +tdiff="$td/test$N.diff" +da="test$N $(date) $RANDOM" +CMD="$TRACE $SOCAT $opts -R $ts - /dev/null" +printf "test $F_n $TEST... " $N +echo "$da" |$CMD >"${tf}" 2>"${te}" +rc=$? +if [ ! -f "$ts" ]; then + $PRINTF "$CANT\n" + if [ "$VERBOSE" ]; then + echo "$CMD" >&2 + cat "${te}" >&2 + fi + numCANT=$((numCANT+1)) + listCANT="$listCANT $N" +elif [ ! -s "$ts" ]; then + $PRINTF "$OK\n" + if [ "$VERBOSE" ]; then + echo "$CMD" >&2 + fi + numOK=$((numOK+1)) +else + $PRINTF "$FAILED\n" + echo "$CMD &" >&2 + cat "${te}" >&2 + numFAIL=$((numFAIL+1)) + listFAIL="$listFAIL $N" +fi +fi # NUMCOND + ;; +esac +PORT=$((PORT+1)) +N=$((N+1)) + + # end of common tests ################################################################################## @@ -15296,11 +15340,15 @@ rc1=$? kill $pid0 2>/dev/null; wait if [ !!! ]; then $PRINTF "$OK\n" +<<<<<<< HEAD <<<<<<< HEAD if [" $VERBOSE" ]; then ======= if [ "$VERBOSE" ]; then >>>>>>> 8e56329... ABSTEACT-LISTEN with option user calls fchown() +======= + if [ "$VERBOSE" ]; then +>>>>>>> 4927d33... Option -R did not only dump right-to-left, but also left-to-right traffic echo "$CMD0 &" >&2 echo "$CMD1" >&2 fi