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

(cherry picked from commit d51dac5f1370bdca1ea20c6b48cdea463f6f5dda)

Details

Provenance
kevansAuthored on Jan 16 2024, 2:55 AM
Parents
rGf0122974fba0: amdsmn(4), amdtemp(4): add support for Zen 4
Branches
Unknown
Tags
Unknown