HomeFreeBSD

kern: tty: fix EOF handling for canonical reads

Description

kern: tty: fix EOF handling for canonical reads

If the read(2) buffer is one byte short of an EOF, then we'll end up
reading the line into the buffer, then re-entering and seeing an EOF at
the beginning of the inq, assuming it's a zero-length line.

Fix this corner-case by searching one more byte than we have available
for an EOF. If we found it, then we'll trim it here; otherwise, we'll
limit our read to just the space we have in the out buffer and the next
read(2) will (potentially) read the remainder of the line.

Fix FIONREAD while we're here to match what an application can expect
read(2) to return -- scan for the first break character in the part of
the input that's been canonicalized, we'll never return more than that.

PR: 276220
Reviewed by: cy, imp (both previous version), kib
Differential Revision: https://reviews.freebsd.org/D43378

Details

Provenance
kevansAuthored on Jan 16 2024, 2:55 AM
Reviewer
cy
Differential Revision
D43378: kern: tty: fix EOF handling for canonical reads
Parents
rG09a43b8790bd: kern: tty: fix ttyinq_read_uio assertion
Branches
Unknown
Tags
Unknown