]> 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, 16 Jan 2024 02:55:58 +0000 (20:55 -0600)
commitd51dac5f1370bdca1ea20c6b48cdea463f6f5dda
treeeb906a7e7f65e0d1fd9c203434e6ee024a548479
parent09a43b8790bdeb97fbecd3ea767c2f599eb4a4d3
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
sys/kern/tty.c
sys/kern/tty_ttydisc.c
sys/sys/ttydisc.h