HomeFreeBSD

kern: tty: fix recanonicalization

Description

kern: tty: fix recanonicalization

ti->ti_begin is actually the offset within the first block that is
unread, so we must use that for our lower bound.

Moving to the previous block has to be done at the end of the loop in
order to correctly handle the case of ti_begin == TTYINQ_DATASIZE. At
that point, lastblock is still the last one with data written and the
next write into the queue would advance lastblock. If we move to the
previous block at the beginning, then we're essentially off by one block
for the entire scan and run the risk of running off the end of the block
queue.

The ti_begin == 0 case is still handled correctly, as we skip the loop
entirely and the linestart gets recorded as the first byte available for
writing. The bit after the loop about moving to the next block is also
still correct, even with both previous fixes in mind: we skipped moving
to the previous block if we hit ti_begin, and off + 1 would in-fact be
a member of the next block from where we're reading if it falls on a
block boundary.

Reported by: dim
Fixes: 522083ffbd1ab ("kern: tty: recanonicalize the buffer on [...]")

Details

Provenance
kevansAuthored on Jan 24 2024, 7:36 PM
Parents
rG8b82f36f8903: pflowctl: fix usage message
Branches
Unknown
Tags
Unknown