]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
kern: tty: fix EOF handling for canonical reads
authorKyle Evans <kevans@FreeBSD.org>
Tue, 16 Jan 2024 02:55:58 +0000 (20:55 -0600)
committerKyle Evans <kevans@FreeBSD.org>
Tue, 30 Jan 2024 17:11:09 +0000 (11:11 -0600)
commit2a05c20339082c19e64f9027f80706b8d24a082d
treedfe79dc2e04d517d8f9e8880af6349dfbc3f48e7
parentf0122974fba0cee78e8bd86351803d855ce85758
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)
sys/kern/tty.c
sys/kern/tty_ttydisc.c
sys/sys/ttydisc.h