HomeFreeBSD

MFC r315005: sh: Fix executing wrong command with ${x#$(y)}$(z).

Description

MFC r315005: sh: Fix executing wrong command with ${x#$(y)}$(z).

The parsed internal representation of words consists of a byte string with a
list of nodes (commands in command substitution). Each unescaped CTLBACKQ or
CTLBACKQ | CTLQUOTE byte corresponds to an entry in the list.

If param in ${param#%##%%word} is not set, the word is not expanded (in a
deviation of POSIX shared with other ash variants and ksh93). Erroneously,
the pointer in the list of commands (argbackq) was not advanced. This caused
the wrong command to be executed later if the outer word contained another
command substitution.

Example:

echo "${unsetvar#$(echo a)}$(echo b)"

wrote "a" but should write "b".

Details

Provenance
jillesAuthored on
Parents
rS320509: In the stdio cleanup push and pop wrappers, always call libc stubs for
Branches
Unknown
Tags
Unknown