[Bug 220587] /bin/sh Incorrect options handling
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Mon Jul 17 22:09:55 UTC 2017
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=220587
Jilles Tjoelker <jilles at FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|New |Open
--- Comment #3 from Jilles Tjoelker <jilles at FreeBSD.org> ---
You are right that FreeBSD sh deviates here, but I do not agree with your
patch. POSIX specifies that -c's command_string is an operand and not an
option-argument (but -o does take an option-argument). Therefore in
sh -ca 'echo $-:$0'
and
sh -c -a 'echo $-:$0'
the allexport option should be set, while in
sh -c 'echo $-:$0' -a
the allexport option should not be set and $0 should be set to "-a".
Your patch fixes the latter case at the cost of breaking the former case, while
the middle case remains broken.
Various shells such as bash, ksh93 and mksh handle all three cases correctly.
Note that this means that passing a command string starting with "-" to popen()
or system() shall not execute that string as a command, since sh will interpret
it as containing options and there will not be a command_string for -c.
A command string starting with "-" can be passed like
sh -c -- '-a; echo continued'
which bash, ksh93 and mksh also support and we do not. The specification for
popen() and system() is unambiguous about the command that should be used,
though, and it does not include "--".
Please forget about the NOHACK code. Apart from the fact that this kind of
thing makes a poor compile-time option, the NOHACK case has been obviously
broken since it was added, because it uses q uninitialized if (*p != '\0'). I
will take it out soon.
The easiest way to run the test suite is to install everything and then run as
root
cd /usr/tests/bin/sh && kyua test
If these directories do not exist, place WITH_TESTS=YES in /etc/src.conf,
rebuild and reinstall.
An uninstalled sh can be tested against installed tests by running
cd /usr/tests/bin/sh && kyua -v
test_suites.FreeBSD.bin.sh.test_shell=/path/to/test/sh test
This latter command might break in the future since this feature should be
provided generically, not specifically to sh.
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the freebsd-standards
mailing list