diff options
| author | blymn <blymn@NetBSD.org> | 2022-10-25 06:20:01 +0000 |
|---|---|---|
| committer | blymn <blymn@NetBSD.org> | 2022-10-25 06:20:01 +0000 |
| commit | 1126286967bbcf2469b53efe9aa8ec37b8cf87c8 (patch) | |
| tree | be1ffab07cfd9d321862510f0c320ddddf3764ff /lib/libcurses | |
| parent | 2c1ee1253dbf1cbda47d36ab7539f32371c5d9ba (diff) | |
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 (limited to 'lib/libcurses')
| -rw-r--r-- | lib/libcurses/attributes.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/libcurses/attributes.c b/lib/libcurses/attributes.c index bdd429f9ee6..76a332407e9 100644 --- a/lib/libcurses/attributes.c +++ b/lib/libcurses/attributes.c @@ -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 @@ attrset(int attr) 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 @@ wcolor_set(WINDOW *win, short pair, void *opts) 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 @@ term_attrs(void) 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 @@ __wattr_on(WINDOW *win, attr_t attr) 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 @@ __wattr_off(WINDOW *win, attr_t attr) 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; |
