diff options
author | Kyle Evans <kevans@FreeBSD.org> | 2024-01-16 02:55:58 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2024-02-07 05:18:59 +0000 |
commit | ba90708fb116a6587a992f0a14fd807f44b72309 (patch) | |
tree | a6e23f10a60aa4bef85cfae634c363fca54af32e | |
parent | 24eb518714f6c681fc5fbb28170b1d74296d24f1 (diff) | |
download | src-ba90708fb116a6587a992f0a14fd807f44b72309.tar.gz src-ba90708fb116a6587a992f0a14fd807f44b72309.zip |
kern: tty: fix ttyinq_read_uio assertion
It's clear from later context that `rlen` was always expected to include
`flen`, as we'll trim `flen` bytes from the end of the read. Relax our
initial assertion to only require the total size less trimmed bytes to
lie within the out buffer size.
While we're here, I note that if we have to read more than one block and
we're trimming from the end then we'll do the wrong thing and omit
`flen` bytes from every block, rather than just the end. Add an
assertion to make sure we're not doing that, but the only caller that
specifies a non-zero `flen` today will only really be doing so if rlen
is entirely within a single buffer.
Approved by: re (cperciva)
Reviewed by: cy, imp
(cherry picked from commit 09a43b8790bdeb97fbecd3ea767c2f599eb4a4d3)
(cherry picked from commit 81ef0de636ff8ba0b8057ced593f2ab92597b1a6)
-rw-r--r-- | sys/kern/tty_inq.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/sys/kern/tty_inq.c b/sys/kern/tty_inq.c index daf3bde77712..0bf7c2fa5b5e 100644 --- a/sys/kern/tty_inq.c +++ b/sys/kern/tty_inq.c @@ -165,7 +165,8 @@ ttyinq_read_uio(struct ttyinq *ti, struct tty *tp, struct uio *uio, size_t rlen, size_t flen) { - MPASS(rlen <= uio->uio_resid); + /* rlen includes flen, flen bytes will be trimmed from the end. */ + MPASS(rlen - flen <= uio->uio_resid); while (rlen > 0) { int error; @@ -193,6 +194,14 @@ ttyinq_read_uio(struct ttyinq *ti, struct tty *tp, struct uio *uio, rlen -= clen; /* + * Caller shouldn't request that we trim anything if we might be + * reading across blocks. We could handle it, but today we do + * not. + */ + if (flen > 0) + MPASS(rlen == 0); + + /* * We can prevent buffering in some cases: * - We need to read the block until the end. * - We don't need to read the block until the end, but |