summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2022-06-02 23:46:21 +0200
committerBenBE <BenBE@geshi.org>2022-06-03 20:11:24 +0200
commit611ea4606f8538abf9c3db839f13c52dbc3a9605 (patch)
tree0bc80ef7a1964b99f61f67354a5d27f4e704fad7
parent4e6ec4a0873c56ca9de63eadf730c5bd677bd8da (diff)
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
-rw-r--r--CRT.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/CRT.c b/CRT.c
index 868f2377..95f8cc13 100644
--- a/CRT.c
+++ b/CRT.c
@@ -1013,9 +1013,11 @@ IGNORE_WCASTQUAL_END
}
void CRT_done() {
- attron(CRT_colors[RESET_COLOR]);
+ int resetColor = CRT_colors ? CRT_colors[RESET_COLOR] : CRT_colorSchemes[COLORSCHEME_DEFAULT][RESET_COLOR];
+
+ attron(resetColor);
mvhline(LINES - 1, 0, ' ', COLS);
- attroff(CRT_colors[RESET_COLOR]);
+ attroff(resetColor);
refresh();
curs_set(1);

© 2014-2024 Faster IT GmbH | imprint | privacy policy