diff --git a/CHANGES b/CHANGES index f390913..d63c274 100644 --- a/CHANGES +++ b/CHANGES @@ -213,6 +213,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: Red Hat issue 1020203: configure checks fail with some compilers. Use case: clang diff --git a/test.sh b/test.sh index 94907ed..6f91144 100755 --- a/test.sh +++ b/test.sh @@ -12537,6 +12537,39 @@ N=$((N+1)) done +# test if option fdout in write only context issues an error +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 # before this paragraph. diff --git a/xio-progcall.c b/xio-progcall.c index e5627d4..27929d1 100644 --- a/xio-progcall.c +++ b/xio-progcall.c @@ -164,8 +164,17 @@ int _xioopen_progcall(int xioflags, /* XIO_RDONLY etc. */ if (!retropt_int(popts, OPT_LEFTFD, &fdi)) { fdo = fdi; } - retropt_int(popts, OPT_LEFTINFD, &fdi); - retropt_int(popts, OPT_LEFTOUTFD, &fdo); + + if (retropt_int(popts, OPT_LEFTINFD, (unsigned short *)&fdi) >= 0) { + if ((xioflags&XIO_ACCMODE) == XIO_RDONLY) { + Error("_xioopen_progcall(): option fdin is useless in read-only mode"); + } + } + if (retropt_int(popts, OPT_LEFTOUTFD, (unsigned short *)&fdo) >= 0) { + if ((xioflags&XIO_ACCMODE) == XIO_WRONLY) { + Error("_xioopen_progcall(): option fdout is useless in write-only mode"); + } + } if (!retropt_int(popts, OPT_RIGHTFD, &rightin)) { rightout = rightin;