backquote expansion bug in /bin/sh ( fix included )

Andrew Atrens atrens at nortelnetworks.com
Wed Feb 4 12:42:01 PST 2004


Hi Folks,

Not sure how long this has been broken but ...

Using the following test script -

-- root at atrens: /usr/dfly/devel/src/bin/sh (14:43) --
# cat bug.sh


test() {
   /bin/echo "hello"
   /bin/echo ""
   /bin/echo ""
   /bin/echo ""
   /bin/echo ""
   /bin/echo ""
   /bin/echo ""
   /bin/echo ""
}

echo ">>`test`<<"


I see the following behaviours -

-- root at atrens: /usr/dfly/devel/src/bin/sh (14:43) --
# zsh bug.sh
>>hello<<

-- root at atrens: /usr/dfly/devel/src/bin/sh (14:43) --
# bash bug.sh
>>hello<<

-- root at atrens: /usr/dfly/devel/src/bin/sh (14:44) --
# ksh bug.sh
>>hello<<

-- root at atrens: /usr/dfly/devel/src/bin/sh (14:44) --
# sh bug.sh
>>hello






<<

When I put ksh, bash, or zsh into 'sh' mode by creating (and using) a 'sh'
link to them their behaviour does not change.

Here's a patch to sh, which fixes this -


"/usr/bin/cvs" -z3 -Q diff -N -b -B -kk  -r 1.3 -r 1.3.2.1 "expand.c"
Index: expand.c
===================================================================
RCS file: /usr/dfly/repo/src/bin/sh/expand.c,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -b -B -r1.3 -r1.3.2.1
472c472
<       for (p--; lastc == '\n'; lastc = *--p)
---
>       for ( ; *(dest-1) == '\n' ; )





I've installed my patched /bin/sh and successfully completed a 'make
buildworld' with it. It would be cool if someone could review/commit this.

Cheers,

Andrew.









More information about the Bugs mailing list