Package: dash
Version: 0.5.8-2.4
Severity: normal
Tags: upstream
X-Debbugs-CC: Michael Prokop <
mpr...@sipwise.com>
Hi!
While tracking an issue with some scripts (described at [I]) we noticed
that dash is not POSIX compliant when parsing the script to invoke
from stdin. In contradiction with POSIX, it does block reads instead
of character-per-character reads to only get the current command,
quoting from POSIX [P]:
,---
| STDIN
|
| […]
|
| When the shell is using standard input and it invokes a command that
| also uses standard input, the shell shall ensure that the standard
| input file pointer points directly after the command it has read
| when the command begins execution. It shall not read ahead in such a
| manner that any characters intended to be read by the invoked
| command are consumed by the shell (whether interpreted by the shell
| or not) or that characters that are not read by the invoked command
| are not seen by the shell. When the command expecting to read
| standard input is started asynchronously by an interactive shell, it
| is unspecified whether characters are read by the command or
| interpreted by the shell.
`---
[I] <
https://michael-prokop.at/blog/2017/05/18/debugging-a-mystery-ssh-causing-strange-exit-codes/>
[P] <
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html>
The following test demonstrates the problem:
,--- sh-stdin.sh ---
#!/bin/sh
: ${TEST_SH:=dash}
$TEST_SH <<"EOF"
echo "Inner: pre"
while read line; do echo "Eat: $line"; done
echo "Inner: post"
exit 3
EOF
echo "Outer: exit code = $?"
`---
,--- test session ---
$ TEST_SH=bash ./sh-stdin
Inner: pre
Eat: echo "Inner: post"
Eat: exit 3
Outer: exit code = 0
$ TEST_SH=dash ./stdin.sh
Inner: pre
Inner: post
Outer: exit code = 3
`---
All other shells that we tested are POSIX compliant, this includes:
bash, ksh, mksh, posh and zsh
Thanks,
Guillem