diff --git a/sys/kern/tty_ttydisc.c b/sys/kern/tty_ttydisc.c --- a/sys/kern/tty_ttydisc.c +++ b/sys/kern/tty_ttydisc.c @@ -153,7 +153,7 @@ * cause the TTY layer to return data in chunks using * the blocksize (except the first and last blocks). */ - clen = ttyinq_findchar(&tp->t_inq, breakc, uio->uio_resid, + clen = ttyinq_findchar(&tp->t_inq, breakc, uio->uio_resid + 1, &lastc); /* No more data. */ @@ -169,10 +169,20 @@ continue; } - /* Don't send the EOF char back to userspace. */ + /* + * Don't send the EOF char back to userspace. Our above call to + * ttyinq_findchar overreads by 1 character in case we would + * otherwise be leaving an EOF for the next read(). We'll trim + * clen back down to uio_resid whether we find our EOF or not. + */ if (CMP_CC(VEOF, lastc)) flen = 1; + /* + * Trim clen back down to the buffer size, since we had + * intentionally over-read. + */ + clen = MIN(uio->uio_resid + flen, clen); MPASS(flen <= clen); /* Read and throw away the EOF character. */