From 8c8f81778084e19071f2be9b44acc8f8aa3a003f Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Tue, 13 Jan 2015 12:12:23 +0100 Subject: [PATCH] Print error on useless fdout,fdin options --- CHANGES | 5 +++++ test.sh | 33 +++++++++++++++++++++++++++++++++ xio-progcall.c | 13 +++++++++++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 8fc2c2f..9dcde43 100644 --- a/CHANGES +++ b/CHANGES @@ -81,6 +81,11 @@ corrections: Help for filan -L was bad, is now corrected to: "follow symbolic links instead of showing their properties" + Address options fdin and fdout were silently ignored when not applicable + due to -u or -U option. Now these combinations are caught as errors. + Test: FDOUT_ERROR + Issue reported by Hendrik. + porting: Socat included instead of POSIX Thanks to John Spencer for reporting this issue. diff --git a/test.sh b/test.sh index 9c6fc56..8274c81 100755 --- a/test.sh +++ b/test.sh @@ -12149,6 +12149,39 @@ N=$((N+1)) done +# give a description of what is tested (a bugfix, a new feature...) +NAME=FDOUT_ERROR +case "$TESTS" in +*%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%$NAME%*) +TEST="$NAME: fdout bails out in write-only context" +# use EXEC in write-only context with option fdout. Expected behaviour: error +if ! eval $NUMCOND; then :; else +tf="$td/test$N.stdout" +te="$td/test$N.stderr" +tdiff="$td/test$N.diff" +da="test$N $(date) $RANDOM" +CMD="$SOCAT $opts -u /dev/null EXEC:cat,fdout=1" +printf "test $F_n $TEST... " $N +$CMD >/dev/null 2>"${te}" +rc=$? +if [ $rc -eq 1 ]; then + $PRINTF "$OK\n" + numOK=$((numOK+1)) +else + $PRINTF "$FAILED\n" + echo "$CMD" + cat "${te}" + echo "command did not terminate with error!" + numFAIL=$((numFAIL+1)) + listFAIL="$listFAIL $N" +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-progcall.c b/xio-progcall.c index 13cd77d..9b2c7fa 100644 --- a/xio-progcall.c +++ b/xio-progcall.c @@ -103,8 +103,17 @@ int _xioopen_foxec(int xioflags, /* XIO_RDONLY etc. */ usepipes = false; } #endif /* HAVE_PTY */ - retropt_ushort(popts, OPT_FDIN, (unsigned short *)&fdi); - retropt_ushort(popts, OPT_FDOUT, (unsigned short *)&fdo); + + if (retropt_ushort(popts, OPT_FDIN, (unsigned short *)&fdi) >= 0) { + if ((xioflags&XIO_ACCMODE) == XIO_RDONLY) { + Error("_xioopen_foxec(): option fdin is useless in read-only mode"); + } + } + if (retropt_ushort(popts, OPT_FDOUT, (unsigned short *)&fdo) >= 0) { + if ((xioflags&XIO_ACCMODE) == XIO_WRONLY) { + Error("_xioopen_foxec(): option fdout is useless in write-only mode"); + } + } if (withfork) { if (!(xioflags&XIO_MAYCHILD)) {