Re: The read builtin erroneously consumes null bytes
Alexis <[email protected]> Sat, 20 Jun 2026 11:52:49 +1000
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <[email protected]> |
"Kerin Millar" <[email protected]> writes: > Consider the following test case. It demonstrates NUL being > consumed by the read builtin, rather than by cat(1) as it should > have been. > > $ printf 'a\n\0bc' | dash -c 'read x; cat' | od -An -t x1 -c > 62 63 > b c POSIX doesn't require a `read` _builtin_, but for the `read` _utility_, it says: > STDIN > > If the -d delim option is not specified, or if it is specified > and > delim is not the null string, the standard input shall contain > zero or > more bytes (which need not form valid characters) and shall not > contain any null bytes. > > If the -d delim option is specified and delim is the null > string, the > standard input shall contain zero or more bytes (which need not > form > valid characters). -- https://pubs.opengroup.org/onlinepubs/9799919799/utilities/read.html#tag_20_100 dash's `read` builtin doesn't have an `-d delim` option, and it seems to me that in such a context, it's reasonable to regard `-d delim` as "not specified", such that stdin isn't allowed to contain any null bytes. Alexis.