Source-Changes-HG archive

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

[src/trunk]: src/lib/libcurses Fix for lib/57050



details:   https://anonhg.NetBSD.org/src/rev/49c03f697aff
branches:  trunk
changeset: 372000:49c03f697aff
user:      blymn <blymn%NetBSD.org@localhost>
date:      Tue Oct 25 06:20:01 2022 +0000

description:
Fix for lib/57050
Perform a sanity check on the window parameter being passed and return
ERR if it is null.  This prevents buggy code crashing.

diffstat:

 lib/libcurses/attributes.c |  31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)

diffs (80 lines):

diff -r 8a68c86974bf -r 49c03f697aff lib/libcurses/attributes.c
--- a/lib/libcurses/attributes.c        Tue Oct 25 00:20:36 2022 +0000
+++ b/lib/libcurses/attributes.c        Tue Oct 25 06:20:01 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: attributes.c,v 1.34 2022/04/12 07:03:04 blymn Exp $    */
+/*     $NetBSD: attributes.c,v 1.35 2022/10/25 06:20:01 blymn Exp $    */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: attributes.c,v 1.34 2022/04/12 07:03:04 blymn Exp $");
+__RCSID("$NetBSD: attributes.c,v 1.35 2022/10/25 06:20:01 blymn Exp $");
 #endif                         /* not lint */
 
 #include "curses.h"
@@ -143,6 +143,9 @@
 int
 wattr_get(WINDOW *win, attr_t *attr, short *pair, void *opts)
 {
+       if (__predict_false(win == NULL))
+               return ERR;
+
        __CTRACE(__CTRACE_ATTR, "wattr_get: win %p\n", win);
        if (attr != NULL) {
                *attr = win->wattr;
@@ -231,6 +234,9 @@
 chtype
 getattrs(WINDOW *win)
 {
+       if (__predict_false(win == NULL))
+               return ERR;
+
        __CTRACE(__CTRACE_ATTR, "getattrs: win %p\n", win);
        return((chtype) win->wattr);
 }
@@ -361,7 +367,12 @@
 static int
 __wattr_on(WINDOW *win, attr_t attr)
 {
-       const TERMINAL *t = win->screen->term;
+       const TERMINAL *t;
+
+       if (__predict_false(win == NULL))
+               return ERR;
+
+       t = win->screen->term;
 
        __CTRACE(__CTRACE_ATTR, "wattr_on: win %p, attr %08x\n", win, attr);
        /* If can enter modes, set the relevant attribute bits. */
@@ -408,7 +419,12 @@
 static int
 __wattr_off(WINDOW *win, attr_t attr)
 {
-       const TERMINAL *t = win->screen->term;
+       const TERMINAL *t;
+
+       if (__predict_false(win == NULL))
+               return ERR;
+
+       t = win->screen->term;
 
        __CTRACE(__CTRACE_ATTR, "wattr_off: win %p, attr %08x\n", win, attr);
        /* If can do exit modes, unset the relevant attribute bits. */
@@ -455,7 +471,12 @@
 static void
 __wcolor_set(WINDOW *win, attr_t attr)
 {
-       const TERMINAL *t = win->screen->term;
+       const TERMINAL *t;
+
+       if (__predict_false(win == NULL))
+               return;
+
+       t = win->screen->term;
 
        /* If another color pair is set, turn that off first. */
        win->wattr &= ~__COLOR;



Home | Main Index | Thread Index | Old Index