Skip to content

Commit 611ea46

Browse files
stoeckmannBenBE
authored andcommitted
Prevent null pointer dereference on early error
If a fatal error occurs before CRT_init has been called, CRT_done dereferences NULL in CRT_colors. Simply check if CRT_crashSettings is not NULL, which is eventually set when CRT_init has been called. If it is not set, then do not try to disable ncurses. Proof of Concept (on Linux): $ ./configure --with-proc=/var/empty $ make $ ./htop
1 parent 4e6ec4a commit 611ea46

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

CRT.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,11 @@ IGNORE_WCASTQUAL_END
10131013
}
10141014

10151015
void CRT_done() {
1016-
attron(CRT_colors[RESET_COLOR]);
1016+
int resetColor = CRT_colors ? CRT_colors[RESET_COLOR] : CRT_colorSchemes[COLORSCHEME_DEFAULT][RESET_COLOR];
1017+
1018+
attron(resetColor);
10171019
mvhline(LINES - 1, 0, ' ', COLS);
1018-
attroff(CRT_colors[RESET_COLOR]);
1020+
attroff(resetColor);
10191021
refresh();
10201022

10211023
curs_set(1);

0 commit comments

Comments
 (0)