Date: Tue, 19 Aug 2008 21:08:52 GMT From: Ed Schouten <ed@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 147836 for review Message-ID: <200808192108.m7JL8qU7006574@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147836 Change 147836 by ed@ed_dull on 2008/08/19 21:08:04 Add an unused example of how we could implement a safer TTY flushing routine for the input path, which would be very useful for utilities like passwd to call, because it guarantees we internally zeroise all buffers. I've not hooked it up to anything yet, but let's hope someone (me?) picks this up after the MPSAFE TTY import. While there, fix some small style(9) issues in tty_*q.c, as I didn't know we had the single line of whitespace rule when I wrote the code in question. Requested by: csjp Affected files ... .. //depot/projects/mpsafetty/sys/kern/tty_inq.c#4 edit .. //depot/projects/mpsafetty/sys/kern/tty_outq.c#4 edit Differences ... ==== //depot/projects/mpsafetty/sys/kern/tty_inq.c#4 (text+ko) ==== @@ -145,6 +145,7 @@ ttyinq_read_uio(struct ttyinq *ti, struct tty *tp, struct uio *uio, size_t rlen, size_t flen) { + MPASS(rlen <= uio->uio_resid); while (rlen > 0) { @@ -261,6 +262,7 @@ ttyinq_set_quotes(struct ttyinq_block *tib, size_t offset, size_t length, int value) { + if (value) { /* Set the bits. */ for (; length > 0; length--, offset++) @@ -336,6 +338,7 @@ void ttyinq_canonicalize(struct ttyinq *ti) { + ti->ti_linestart = ti->ti_reprint = ti->ti_end; ti->ti_startblock = ti->ti_reprintblock = ti->ti_lastblock; } @@ -369,12 +372,29 @@ void ttyinq_flush(struct ttyinq *ti) { + ti->ti_begin = 0; ti->ti_linestart = 0; ti->ti_reprint = 0; ti->ti_end = 0; } +#if 0 +void +ttyinq_flush_safe(struct ttyinq *ti) +{ + struct ttyinq_block *tib; + + ttyinq_flush(ti); + + /* Zero all data in the input queue to make it more safe */ + TAILQ_FOREACH(tib, &ti->ti_list, tib_list) { + bzero(&tib->tib_quotes, sizeof tib->tib_quotes); + bzero(&tib->tib_data, sizeof tib->tib_data); + } +} +#endif + int ttyinq_peekchar(struct ttyinq *ti, char *c, int *quote) { @@ -396,6 +416,7 @@ void ttyinq_unputchar(struct ttyinq *ti) { + MPASS(ti->ti_linestart < ti->ti_end); if (--ti->ti_end % TTYINQ_DATASIZE == 0) { @@ -413,6 +434,7 @@ void ttyinq_reprintpos_set(struct ttyinq *ti) { + ti->ti_reprint = ti->ti_end; ti->ti_reprintblock = ti->ti_lastblock; } @@ -420,6 +442,7 @@ void ttyinq_reprintpos_reset(struct ttyinq *ti) { + ti->ti_reprint = ti->ti_linestart; ti->ti_reprintblock = ti->ti_startblock; } @@ -454,6 +477,7 @@ ttyinq_line_iterate_from_linestart(struct ttyinq *ti, ttyinq_line_iterator_t *iterator, void *data) { + ttyinq_line_iterate(ti, iterator, data, ti->ti_linestart, ti->ti_startblock); } @@ -462,6 +486,7 @@ ttyinq_line_iterate_from_reprintpos(struct ttyinq *ti, ttyinq_line_iterator_t *iterator, void *data) { + ttyinq_line_iterate(ti, iterator, data, ti->ti_reprint, ti->ti_reprintblock); } @@ -469,6 +494,7 @@ static void ttyinq_startup(void *dummy) { + ttyinq_zone = uma_zcreate("ttyinq", sizeof(struct ttyinq_block), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); } ==== //depot/projects/mpsafetty/sys/kern/tty_outq.c#4 (text+ko) ==== @@ -70,6 +70,7 @@ void ttyoutq_flush(struct ttyoutq *to) { + to->to_begin = 0; to->to_end = 0; } @@ -197,6 +198,7 @@ int ttyoutq_read_uio(struct ttyoutq *to, struct tty *tp, struct uio *uio) { + while (uio->uio_resid > 0) { int error; struct ttyoutq_block *tob; @@ -355,6 +357,7 @@ static void ttyoutq_startup(void *dummy) { + ttyoutq_zone = uma_zcreate("ttyoutq", sizeof(struct ttyoutq_block), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808192108.m7JL8qU7006574>