Module Name:    src
Committed By:   blymn
Date:           Tue Oct 25 06:20:01 UTC 2022

Modified Files:
        src/lib/libcurses: attributes.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/libcurses/attributes.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libcurses/attributes.c
diff -u src/lib/libcurses/attributes.c:1.34 src/lib/libcurses/attributes.c:1.35
--- src/lib/libcurses/attributes.c:1.34	Tue Apr 12 07:03:04 2022
+++ src/lib/libcurses/attributes.c	Tue Oct 25 06:20:01 2022
@@ -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
 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;

Reply via email to