diff --git a/CHANGES b/CHANGES index df0bf2a..4dcb9c8 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,10 @@ corrections: EXEC and SYSTEM with stderr injected socat messages into the data stream. test: EXECSTDERRLOG + when the EXEC address got a string with consecutive spaces it created + additional empty arguments (thanks to Olivier Hervieu for reporting + this bug) + ####################### V 1.6.0.1: new features: diff --git a/VERSION b/VERSION index bb1254e..6d51c99 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -"1.6.0.1+ip4bind+recvfromfork+x64+execstderr" +"1.6.0.1+ip4bind+recvfromfork+x64+execstderr+execspaces" diff --git a/test.sh b/test.sh index 60ba633..29d5359 100755 --- a/test.sh +++ b/test.sh @@ -8261,6 +8261,41 @@ PORT=$((PORT+1)) N=$((N+1)) +# there was a bug in parsing the arguments of exec: consecutive spaces resulted +# in additional empty arguments +NAME=EXECSPACES +case "$TESTS" in +*%functions%*|*%exec%*|*%parse%*|*%$NAME%*) +TEST="$NAME: correctly parse exec with consecutive spaces" +$PRINTF "test $F_n $TEST... " $N +tf="$td/test$N.stdout" +te="$td/test$N.stderr" +da="test$N $(date) $RANDOM" +tdiff="$td/test$N.diff" +# put the test data as first argument after two spaces. expect the data in the +# first argument of the exec'd command. +$SOCAT $opts -u "exec:\"bash -c \\\"echo \$1\\\" \\\"\\\" \\\"$da\\\"\"" - >"$tf" 2>"$te" +rc=$? +echo "$da" |diff - "$tf" >"$tdiff" +if [ "$rc" -ne 0 ]; then + $PRINTF "$FAILED: $SOCAT:\n" + cat "$te" + numFAIL=$((numFAIL+1)) +elif [ -s "$tdiff" ]; then + $PRINTF "$FAILED: $SOCAT:\n" + echo diff: + cat "$tdiff" + if [ -n "$debug" ]; then cat $te; fi + numFAIL=$((numFAIL+1)) +else + $PRINTF "$OK\n" + if [ -n "$debug" ]; then cat $te; fi + numOK=$((numOK+1)) +fi +esac +N=$((N+1)) + + echo "summary: $((N-1)) tests; $numOK ok, $numFAIL failed, $numCANT could not be performed" if [ "$numFAIL" -gt 0 ]; then diff --git a/xio-exec.c b/xio-exec.c index 0e2f09d..7a6958c 100644 --- a/xio-exec.c +++ b/xio-exec.c @@ -83,11 +83,11 @@ static int xioopen_exec(int argc, const char *argv[], struct opt *opts, if (pargv[0] == NULL) pargv[0] = token; else ++pargv[0]; pargc = 1; while (*strp == ' ') { + while (*++strp == ' ') ; if ((pargc & 0x07) == 0) { pargv = Realloc(pargv, (pargc+8)*sizeof(char *)); if (pargv == NULL) return STAT_RETRYLATER; } - ++strp; pargv[pargc++] = tokp; if (nestlex(&strp, &tokp, &len, ends, hquotes, squotes, nests, true, true, false) < 0) {