Skip to content

Commit

Permalink
Option -R did not only dump right-to-left, but also left-to-right tra…
Browse files Browse the repository at this point in the history
…ffic
  • Loading branch information
Gerhard Rieger committed Oct 31, 2021
1 parent a390dfc commit 1a1cbb1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions socat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
50 changes: 49 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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

##################################################################################
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1a1cbb1

Please sign in to comment.