DASH Shell discussions
 help / color / mirror / Atom feed
From: Alexis <flexibeast@gmail.com>
To: dash@vger.kernel.org
Cc: "Sam James" <sam@gentoo.org>
Subject: Re: The read builtin erroneously consumes null bytes
Date: Sat, 20 Jun 2026 11:52:49 +1000	[thread overview]
Message-ID: <87h5myx9ji.fsf@gmail.com> (raw)
In-Reply-To: <bf5516e9-e59f-444a-81c6-7b112b71563a@app.fastmail.com> (Kerin Millar's message of "Fri, 19 Jun 2026 06:04:27 +0100")

"Kerin Millar" <kfm@plushkava.net> 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.

  reply	other threads:[~2026-06-20  1:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-19  5:04 The read builtin erroneously consumes null bytes Kerin Millar
2026-06-20  1:52 ` Alexis [this message]
2026-06-20  2:51   ` Harald van Dijk
2026-06-20  5:26 ` Herbert Xu
2026-06-20  5:50   ` Kerin Millar
2026-06-20  9:23     ` [PATCH] input: Fix overeager NUL deletion in SMALL mode Herbert Xu
2026-06-20 10:40       ` Kerin Millar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h5myx9ji.fsf@gmail.com \
    --to=flexibeast@gmail.com \
    --cc=dash@vger.kernel.org \
    --cc=sam@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox