From b1b257367ed19bea3ee42eb90df6e7b0973bbb39 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 13 Sep 2009 18:45:59 +0000 Subject: [PATCH] Make sure we never place the cursor outside the screen. For some vague reason, it may be possible that scp->cursor_pos exceeds scp->ysize * scp->xsize. This means that teken_set_cursor() may get called with an invalid position. Just ignore the old cursor position in this case. Reported by: Paul B. Mahol MFC after: 1 month --- sys/dev/syscons/scterm-teken.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sys/dev/syscons/scterm-teken.c b/sys/dev/syscons/scterm-teken.c index f08a3cb8de2f..3c8a57a981c8 100644 --- a/sys/dev/syscons/scterm-teken.c +++ b/sys/dev/syscons/scterm-teken.c @@ -137,9 +137,12 @@ scteken_init(scr_stat *scp, void **softc, int code) tp.tp_col = scp->xsize; teken_set_winsize(&ts->ts_teken, &tp); - tp.tp_row = scp->cursor_pos / scp->xsize; - tp.tp_col = scp->cursor_pos % scp->xsize; - teken_set_cursor(&ts->ts_teken, &tp); + if (scp->cursor_pos < scp->ysize * scp->xsize) { + /* Valid old cursor position. */ + tp.tp_row = scp->cursor_pos / scp->xsize; + tp.tp_col = scp->cursor_pos % scp->xsize; + teken_set_cursor(&ts->ts_teken, &tp); + } break; }