From 59fcc4ce0f47aa511c3148317a1d15f5c04125c2 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Fri, 15 May 1998 21:35:53 +0000 Subject: [PATCH] Low level use of 'vidattr()' can cause a NULL pointer to be dereferenced. This is because 'SP' is only initialized via 'newterm()' (which is not required if you are going to interact with the 'terminfo' database without using 'ncurses'). PR: 6648 Submitted by: Max Euston --- lib/libncurses/lib_vidattr.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/libncurses/lib_vidattr.c b/lib/libncurses/lib_vidattr.c index 0bb56757d94b..ef8213906227 100644 --- a/lib/libncurses/lib_vidattr.c +++ b/lib/libncurses/lib_vidattr.c @@ -71,13 +71,14 @@ int fg, bg; } } -#define previous_attr SP->_current_attr - int vidputs(chtype newmode, int (*outc)(int)) { -chtype turn_off = (~newmode & previous_attr) & ~A_COLOR; -chtype turn_on = (newmode & ~previous_attr) & ~A_COLOR; -int pair, current_pair; +static chtype previous_attr=0; +chtype turn_off,turn_on; +int pair, current_pair; + + if (SP) + previous_attr = SP->_current_attr; T(("vidputs(%x) called %s", newmode, _traceattr(newmode))); T(("previous attribute was %s", _traceattr(previous_attr))); @@ -85,6 +86,9 @@ int pair, current_pair; if (newmode == previous_attr) return OK; + turn_off = (~newmode & previous_attr) & ~A_COLOR; + turn_on = (newmode & ~previous_attr) & ~A_COLOR; + pair = PAIR_NUMBER(newmode); current_pair = PAIR_NUMBER(previous_attr); @@ -184,6 +188,8 @@ int pair, current_pair; } previous_attr = newmode; + if (SP) + SP->_current_attr = previous_attr; T(("vidputs finished")); return OK;