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 @@ -822,7 +822,9 @@ /* Loop back through inq until we hit the * leading byte. */ while (CTL_UTF8_CONT(c) && nb < UTF8_STACKBUF) { - ttyinq_peekchar(&tp->t_inq, &c, "e); + /* Check if we've reached the beginning of the line. */ + if(ttyinq_peekchar(&tp->t_inq, &c, "e) != 0) + break; ttyinq_unputchar(&tp->t_inq); bytes[curidx] = c; curidx--;