Bug in #! processing - One More Time

Garance A Drosehn gad at FreeBSD.org
Sun May 15 01:53:38 PDT 2005


At 9:09 PM +0300 5/13/05, Maxim Sobolev wrote:
>Garance A Drosihn wrote:
>
>>Note that I'm not just "running this through buildworld".  That's
>>how all the previous changes were tested, too.  I have a whole
>>battery of tests that I've been slogging through.
>
>Well, I'd suggest you to put those tests into src/tools/regression,
>to ensure that this won't be broken occasionally in the future.

Some of the testing has to do with things outside of imgact_shell.c
itself.  This thread started out with a change that made to /bin/sh
which worked fine in -current, but then didn't work in -stable due
to a minor change in imgact_shell.c.  So I'm a bit paranoid.

I haven't been testing with your code, but if you have that code
installed, then you might try the following shell script:

    #!/usr/bin/env BLAH=aBc BLAH2=OtheR /bin/sh
    #
    echo $BLAH $BLAH2

Assuming your change to works about the same as mine, that script
should be an infinite loop.  That's because the historical code
would startup 'env' with:

DBG:	arg[ 0] = '/usr/bin/env'
DBG:	arg[ 1] = 'BLAH=aBc'
DBG:	arg[ 2] = 'BLAH2=OtheR'
DBG:	arg[ 3] = '/bin/sh'
DBG:	arg[ 4] = '/tmp/shelltest3'

While the new code starts it up with:

DBG:	arg[ 0] = '/usr/bin/env'
DBG:	arg[ 1] = 'BLAH=aBc BLAH2=OtheR /bin/sh'
DBG:	arg[ 2] = '/tmp/shelltest3'

This threw me at first, because I have actually used that construct
to start out some scripts.  But it turns out that trick causes the
exact same looping on solaris and linux, so I guess I was just
lucky that I never tried it on anything but FreeBSD!  I wonder if
anyone else has used that.

It also looks like something goes wrong with /bin/sh when options
are given on the #!-line, which may be left-over from my previous
change to it.  I haven't tracked that down yet, but I want to
understand that before committing the fix we want.

My guess is that those are the only two programs in the base system
which need to care about this change, but the update I have also
provides a kludge (which would be undocumented and TEMPORARY) to
give people a way to get the historical parsing-behavior if they
needed it for some script.  I'm not sure if I'll commit that part,
but it's useful for my testing.

-- 
Garance Alistair Drosehn     =      gad at gilead.netel.rpi.edu
Senior Systems Programmer               or   gad at FreeBSD.org
Rensselaer Polytechnic Institute;             Troy, NY;  USA


More information about the freebsd-arch mailing list