bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: minor: "read line" may read several lines if stdin is a tty


From: Stephane Chazelas
Subject: Re: minor: "read line" may read several lines if stdin is a tty
Date: Wed, 27 Aug 2014 20:20:53 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

2014-08-27 08:10:01 -0400, Chet Ramey:
> On 8/25/14, 4:24 PM, Stephane Chazelas wrote:
> > If you run (here testing on Linux):
> > 
> >   bash -c 'read a; echo "<$a>"; tr b c'
> > 
> > And enter aaa<Ctrl-V><Ctrl-J>bbb<Return>
> > 
> > You see "<aaa>", but not "ccc". That's because "read" reads up
> > to 128 bytes of data in one read(2) invocation instead of
> > reading one byte at a time like on other types on non-seekable
> > files.
> 
> While this is true, it's not complete.  Bash relies on the terminal
> driver returning newline-delimited lines when reading from the
> terminal.  If you try to fool it, you can probably succeed.
[...]

I agree <Ctrl-V><Ctrl-J> is clearly an attempt at fooling it and
it's reasonable to expect a read on a terminal in canonical mode
to return a single line.


However, one could imagine using bash's read to get data off a
tty device not in canonical mode (a serial device used as just a
serial device), or any other non-terminal character device for
that matter (a "strace bash -c 'read < /dev/urandom'" reveals
there's an issue there as well), and that would be more of a
problem.

Again, not a big one (hence the [minor] tag) but still a
non-POSIX conformance and bash seems to be the only shell with
the problem (though ksh93 has its own bugs as usual).

-- 
Stephane



reply via email to

[Prev in Thread] Current Thread [Next in Thread]