Re: sh(1) read: add LINE_MAX safeguard and "-n" option

Robert Elz <[email protected]>
Newsgroups gmane.os.netbsd.devel.userlevel
Message-ID <[email protected]>
    Date:        Wed, 25 Sep 2024 21:01:12 +0700
    From:        Robert Elz <[email protected]>
    Message-ID:  <[email protected]>

This isn't avoiding adding a -n that works, but a possible simpler change
that might help, is much easier to install properly, should break nothing,
and I think will probably avoid the problem that is being observed.

That is, currently the read builtin simply ignores \0 bytes in the input,
except if \0 is the delimiter character.   We could change that, and make
\0 an error - POSIX specifies that the input shall not contain \0 chars
unless -d has been used to make \0 the delimiter character.

If that change got made, I suspect that the read would terminate quite
quickly on non-text files, and text files will end at the first \n.

Would that be a useful first step at least?

If I do that, I'd probably add an option to retain the current behaviour,
just in case there's something (inappropriately) relying upon it.

kre
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.