EXEC address with consecutive spaces created additional empty arguments

This commit is contained in:
Gerhard Rieger 2008-07-17 21:49:52 +02:00
parent ad4bd0d9db
commit ae368e7cb9
4 changed files with 41 additions and 2 deletions

View file

@ -12,6 +12,10 @@ corrections:
EXEC and SYSTEM with stderr injected socat messages into the data EXEC and SYSTEM with stderr injected socat messages into the data
stream. test: EXECSTDERRLOG 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: ####################### V 1.6.0.1:
new features: new features:

View file

@ -1 +1 @@
"1.6.0.1+ip4bind+recvfromfork+x64+execstderr" "1.6.0.1+ip4bind+recvfromfork+x64+execstderr+execspaces"

35
test.sh
View file

@ -8261,6 +8261,41 @@ PORT=$((PORT+1))
N=$((N+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" echo "summary: $((N-1)) tests; $numOK ok, $numFAIL failed, $numCANT could not be performed"
if [ "$numFAIL" -gt 0 ]; then if [ "$numFAIL" -gt 0 ]; then

View file

@ -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]; if (pargv[0] == NULL) pargv[0] = token; else ++pargv[0];
pargc = 1; pargc = 1;
while (*strp == ' ') { while (*strp == ' ') {
while (*++strp == ' ') ;
if ((pargc & 0x07) == 0) { if ((pargc & 0x07) == 0) {
pargv = Realloc(pargv, (pargc+8)*sizeof(char *)); pargv = Realloc(pargv, (pargc+8)*sizeof(char *));
if (pargv == NULL) return STAT_RETRYLATER; if (pargv == NULL) return STAT_RETRYLATER;
} }
++strp;
pargv[pargc++] = tokp; pargv[pargc++] = tokp;
if (nestlex(&strp, &tokp, &len, ends, hquotes, squotes, nests, if (nestlex(&strp, &tokp, &len, ends, hquotes, squotes, nests,
true, true, false) < 0) { true, true, false) < 0) {