Prevent division by zero errors in sc_mouse_move()

by explicitly setting sc->font_width, in the same
places where sc->font_size is set, instead of
relying on the default initialized value of 0 for sc->font_width.

PR:		kern/84836
Reported by:	Andrey V. Elsukov <bu7cher at yandex dot ru>
MFC after:	2 days
This commit is contained in:
Craig Rodrigues 2005-08-30 18:58:17 +00:00
parent f954ec0bcf
commit 86330afe35
5 changed files with 17 additions and 14 deletions

View File

@ -126,7 +126,7 @@ sc_mouse_move(scr_stat *scp, int x, int y)
s = spltty();
scp->mouse_xpos = scp->mouse_oldxpos = x;
scp->mouse_ypos = scp->mouse_oldypos = y;
if (scp->font_size <= 0)
if (scp->font_size <= 0 || scp->font_width <= 0)
scp->mouse_pos = scp->mouse_oldpos = 0;
else
scp->mouse_pos = scp->mouse_oldpos =

View File

@ -70,7 +70,7 @@ vesa_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *
case SW_TEXT_132x60:
if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0);
return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0);
/* text modes */
case SW_VESA_C80x60:
@ -81,7 +81,7 @@ vesa_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *
if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
mode = (cmd & 0xff) + M_VESA_BASE;
return sc_set_text_mode(scp, tp, mode, 0, 0, 0);
return sc_set_text_mode(scp, tp, mode, 0, 0, 0, 0);
/* graphics modes */
case SW_VESA_32K_320: case SW_VESA_64K_320:

View File

@ -133,7 +133,7 @@ typedef struct old_video_info {
int
sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize,
int fontsize)
int fontsize, int fontwidth)
{
video_info_t info;
u_char *font;
@ -213,6 +213,7 @@ sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize,
scp->ypixel = scp->ysize*fontsize;
scp->font = font;
scp->font_size = fontsize;
scp->font_width = fontwidth;
/* allocate buffers */
sc_alloc_scr_buffer(scp, TRUE, TRUE);
@ -317,7 +318,7 @@ sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode)
int
sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
int fontsize)
int fontsize, int fontwidth)
{
#ifndef SC_PIXEL_MODE
return ENODEV;
@ -429,6 +430,7 @@ sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
scp->yoff = (scp->ypixel/fontsize - ysize)/2;
scp->font = font;
scp->font_size = fontsize;
scp->font_width = fontwidth;
/* allocate buffers */
sc_alloc_scr_buffer(scp, TRUE, TRUE);
@ -554,7 +556,7 @@ sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread *
if (info.vi_flags & V_INFO_GRAPHICS)
return sc_set_graphics_mode(scp, tp, *(int *)data);
else
return sc_set_text_mode(scp, tp, *(int *)data, 0, 0, 0);
return sc_set_text_mode(scp, tp, *(int *)data, 0, 0, 0, 0);
#endif /* SC_NO_MODE_CHANGE */
case OLD_CONS_MODEINFO: /* get mode information (old infterface) */
@ -653,7 +655,7 @@ sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread *
#endif
if (!(adp->va_flags & V_ADP_MODECHANGE))
return ENODEV;
return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0);
return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0);
/* GRAPHICS MODES */
case SW_BG320: case SW_BG640:
@ -746,7 +748,7 @@ sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread *
return EINVAL;
if (scp->status & GRAPHICS_MODE)
return sc_set_pixel_mode(scp, tp, scp->xsize, scp->ysize,
scp->font_size);
scp->font_size, scp->font_width);
s = spltty();
if ((error = sc_clean_up(scp))) {
splx(s);
@ -789,7 +791,7 @@ sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread *
if (ISUNKNOWNSC(scp) || ISTEXTSC(scp))
return ENODEV;
return sc_set_pixel_mode(scp, tp, ((int *)data)[0], ((int *)data)[1],
((int *)data)[2]);
((int *)data)[2], 8);
#endif /* SC_PIXEL_MODE */
case KDGETMODE: /* get current mode of this (virtual) console */

View File

@ -358,7 +358,7 @@ sc_attach_unit(int unit, int flags)
splash_term(sc->adp);
#endif
sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
sc->initial_mode = M_VESA_800x600;
#ifdef DEV_SPLASH
/* put up the splash again! */
@ -510,7 +510,7 @@ scopen(struct cdev *dev, int flag, int mode, struct thread *td)
if (scp == NULL) {
scp = SC_STAT(dev) = alloc_scp(sc, SC_VTY(dev));
if (ISGRAPHSC(scp))
sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
}
if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
tp->t_winsize.ws_col = scp->xsize;

View File

@ -606,10 +606,11 @@ int sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data,
/* scvidctl.c */
int sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode,
int xsize, int ysize, int fontsize);
int xsize, int ysize, int fontsize,
int font_width);
int sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode);
int sc_set_pixel_mode(scr_stat *scp, struct tty *tp,
int xsize, int ysize, int fontsize);
int sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize,
int ysize, int fontsize, int font_width);
int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
struct thread *td);