Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/wscons Do much more sanity checks when handling entr...



details:   https://anonhg.NetBSD.org/src/rev/8e22c06f98d8
branches:  trunk
changeset: 552211:8e22c06f98d8
user:      manu <manu%NetBSD.org@localhost>
date:      Sun Sep 21 18:47:59 2003 +0000

description:
Do much more sanity checks when handling entries in the sc_scr array
of struct wsdisplay_softc. Unused entries are NULL, and there were
a lot of places where we did not checked that the caller did not
requested an operation on a NULL entry.

While we are there, one bit of KNFification, and make return code more
consistent by always returning the same code (EINVAL) when a screen
number higer than the maximum is requested.

diffstat:

 sys/dev/wscons/wsdisplay.c |  60 +++++++++++++++++++++++++++++----------------
 1 files changed, 38 insertions(+), 22 deletions(-)

diffs (179 lines):

diff -r 69a57026a756 -r 8e22c06f98d8 sys/dev/wscons/wsdisplay.c
--- a/sys/dev/wscons/wsdisplay.c        Sun Sep 21 18:40:38 2003 +0000
+++ b/sys/dev/wscons/wsdisplay.c        Sun Sep 21 18:47:59 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wsdisplay.c,v 1.75 2003/06/29 22:31:02 fvdl Exp $ */
+/* $NetBSD: wsdisplay.c,v 1.76 2003/09/21 18:47:59 manu Exp $ */
 
 /*
  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsdisplay.c,v 1.75 2003/06/29 22:31:02 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsdisplay.c,v 1.76 2003/09/21 18:47:59 manu Exp $");
 
 #include "opt_wsdisplay_compat.h"
 #include "opt_compat_netbsd.h"
@@ -415,8 +415,7 @@
 
        if (idx < 0 || idx >= WSDISPLAY_MAXSCREEN)
                return (EINVAL);
-       scr = sc->sc_scr[idx];
-       if (!scr)
+       if ((scr = sc->sc_scr[idx]) == NULL)
                return (ENXIO);
 
        if (scr->scr_dconf == &wsdisplay_console_conf ||
@@ -693,8 +692,7 @@
 
        if (WSDISPLAYSCREEN(dev) >= WSDISPLAY_MAXSCREEN)
                return (ENXIO);
-       scr = sc->sc_scr[WSDISPLAYSCREEN(dev)];
-       if (!scr)
+       if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
                return (ENXIO);
 
        if (WSSCREEN_HAS_TTY(scr)) {
@@ -752,7 +750,8 @@
        if (ISWSDISPLAYCTL(dev))
                return (0);
 
-       scr = sc->sc_scr[WSDISPLAYSCREEN(dev)];
+       if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
+               return (0);
 
        if (WSSCREEN_HAS_TTY(scr)) {
                if (scr->scr_hold_screen) {
@@ -812,7 +811,8 @@
        if (ISWSDISPLAYCTL(dev))
                return (0);
 
-       scr = sc->sc_scr[WSDISPLAYSCREEN(dev)];
+       if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
+               return (ENXIO);
 
        if (!WSSCREEN_HAS_TTY(scr))
                return (ENODEV);
@@ -837,7 +837,8 @@
        if (ISWSDISPLAYCTL(dev))
                return (0);
 
-       scr = sc->sc_scr[WSDISPLAYSCREEN(dev)];
+       if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
+               return (ENXIO);
 
        if (!WSSCREEN_HAS_TTY(scr))
                return (ENODEV);
@@ -861,7 +862,8 @@
        if (ISWSDISPLAYCTL(dev))
                return (0);
 
-       scr = sc->sc_scr[WSDISPLAYSCREEN(dev)];
+       if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
+               return (ENXIO);
 
        if (!WSSCREEN_HAS_TTY(scr))
                return (ENODEV);
@@ -882,7 +884,9 @@
        if (ISWSDISPLAYCTL(dev))
                return (1);
 
-       scr = sc->sc_scr[WSDISPLAYSCREEN(dev)];
+       if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
+               return (1);
+       
 
        if (WSSCREEN_HAS_TTY(scr))
                return (ttykqfilter(dev, kn));
@@ -904,7 +908,8 @@
        if (ISWSDISPLAYCTL(dev))
                panic("wsdisplaytty() on ctl device");
 
-       scr = sc->sc_scr[WSDISPLAYSCREEN(dev)];
+       if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
+               return NULL;
 
        return (scr->scr_tty);
 }
@@ -931,7 +936,8 @@
        if (ISWSDISPLAYCTL(dev))
                return (wsdisplay_cfg_ioctl(sc, cmd, data, flag, p));
 
-       scr = sc->sc_scr[WSDISPLAYSCREEN(dev)];
+       if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
+               return (ENXIO);
 
        if (WSSCREEN_HAS_TTY(scr)) {
                tp = scr->scr_tty;
@@ -1246,7 +1252,8 @@
        if (ISWSDISPLAYCTL(dev))
                return (-1);
 
-       scr = sc->sc_scr[WSDISPLAYSCREEN(dev)];
+       if ((scr = sc->sc_scr[WSDISPLAYSCREEN(dev)]) == NULL)
+               return (-1);
 
        if (!(scr->scr_flags & SCR_GRAPHICS))
                return (-1);
@@ -1269,7 +1276,11 @@
                return;
        }
        sc = device_lookup(&wsdisplay_cd, WSDISPLAYUNIT(tp->t_dev));
-       scr = sc->sc_scr[WSDISPLAYSCREEN(tp->t_dev)];
+       if ((scr = sc->sc_scr[WSDISPLAYSCREEN(tp->t_dev)]) == NULL) {
+               splx(s);
+               return; 
+       }
+
        if (scr->scr_hold_screen) {
                tp->t_state |= TS_TIMEOUT;
                splx(s);
@@ -1302,8 +1313,8 @@
 
                if (!(scr->scr_flags & SCR_GRAPHICS)) {
                        KASSERT(WSSCREEN_HAS_EMULATOR(scr));
-                       (*scr->scr_dconf->wsemul->output)(scr->scr_dconf->wsemulcookie,
-                                                         buf, n, 0);
+                       (*scr->scr_dconf->wsemul->output)
+                           (scr->scr_dconf->wsemulcookie, buf, n, 0);
                }
                ndflush(&tp->t_outq, n);
        }
@@ -1607,9 +1618,12 @@
        int s, res = 0;
        struct wsscreen *scr;
 
-       if (no != WSDISPLAY_NULLSCREEN &&
-           (no < 0 || no >= WSDISPLAY_MAXSCREEN || !sc->sc_scr[no]))
-               return (ENXIO);
+       if (no != WSDISPLAY_NULLSCREEN) {
+               if ((no < 0 || no >= WSDISPLAY_MAXSCREEN))
+                       return (EINVAL);
+               if (sc->sc_scr[no] == NULL)
+                       return (ENXIO);
+       }
 
        wsdisplay_stat_inject(dev, WSCONS_EVENT_SCREEN_SWITCH, no);
 
@@ -1828,7 +1842,8 @@
        if (!wsdisplay_console_initted)
                return;
 
-       if (wsdisplay_console_device != NULL &&
+       if ((wsdisplay_console_device != NULL) && 
+           (wsdisplay_console_device->sc_scr[0] != NULL) &&
            (wsdisplay_console_device->sc_scr[0]->scr_flags & SCR_GRAPHICS))
                return;
 
@@ -1888,7 +1903,8 @@
 
        if (wsdisplay_console_device != NULL) {
                sc = wsdisplay_console_device;
-               scr = sc->sc_scr[0];
+               if ((scr = sc->sc_scr[0]) == NULL)
+                       return;
                (*sc->sc_accessops->show_screen)(sc->sc_accesscookie,
                                                 scr->scr_dconf->emulcookie,
                                                 0, NULL, NULL);



Home | Main Index | Thread Index | Old Index