diff options
author | Kyle Evans <kevans@FreeBSD.org> | 2024-01-16 02:55:58 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2024-02-06 15:31:17 +0000 |
commit | a8aa5ba3db694f97d21e946d6392c527af31f05b (patch) | |
tree | 1eadce06252eb70ebc04157ca11e2eb893e0683a | |
parent | afb21c3a5910fee2e6792121302840c5c2a69369 (diff) | |
download | src-a8aa5ba3db694f97d21e946d6392c527af31f05b.tar.gz src-a8aa5ba3db694f97d21e946d6392c527af31f05b.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.
Reviewed by: cy, imp
(cherry picked from commit 09a43b8790bdeb97fbecd3ea767c2f599eb4a4d3)
-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 |