about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authornia <nia@netbsd.org>2020-09-04 12:59:20 +0200
committernia <nia@netbsd.org>2020-09-04 12:59:20 +0200
commitce67753423389340cf0de0821537c04259288e71 (patch)
tree53748ccbd899dac7e5538486ed2e3ed4c795a0d8 /src
parent52e9be4abc7b0de357bc73d2e88696a97de7e4db (diff)
downloadprofani-tty-ce67753423389340cf0de0821537c04259288e71.tar.gz
Avoid passing NULL pointers to curses functions.
This allows profanity to work without segfaulting from NULL
pointer dereferences when used with NetBSD libcurses.

Basic functionality was tested, there may be more NULL pointer
issues hiding.
Diffstat (limited to 'src')
-rw-r--r--src/ui/inputwin.c4
-rw-r--r--src/ui/rosterwin.c21
-rw-r--r--src/ui/window.c7
3 files changed, 23 insertions, 9 deletions
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 44a1ac47..5da6ae97 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -308,7 +308,9 @@ _inp_win_update_virtual(void)
 {
     int wcols = getmaxx(stdscr);
     int row = screen_inputwin_row();
-    pnoutrefresh(inp_win, 0, pad_start, row, 0, row, wcols - 2);
+    if (inp_win != NULL) {
+        pnoutrefresh(inp_win, 0, pad_start, row, 0, row, wcols - 2);
+    }
 }
 
 static void
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index 3375414c..7c4468d8 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -95,7 +95,10 @@ rosterwin_roster(void)
 
     ProfLayoutSplit* layout = (ProfLayoutSplit*)console->layout;
     assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK);
-    werase(layout->subwin);
+
+    if (layout->subwin != NULL) {
+        werase(layout->subwin);
+    }
 
     char* roomspos = prefs_get_string(PREF_ROSTER_ROOMS_POS);
     if (prefs_get_boolean(PREF_ROSTER_ROOMS) && (g_strcmp0(roomspos, "first") == 0)) {
@@ -1106,9 +1109,11 @@ _rosterwin_contacts_header(ProfLayoutSplit* layout, const char* const title, GSL
 
     gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
 
-    wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-    win_sub_print(layout->subwin, header->str, FALSE, wrap, 1);
-    wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+    if (layout->subwin != NULL) {
+        wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+        win_sub_print(layout->subwin, header->str, FALSE, wrap, 1);
+        wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+    }
 
     g_string_free(header, TRUE);
 }
@@ -1166,9 +1171,11 @@ _rosterwin_rooms_header(ProfLayoutSplit* layout, GList* rooms, char* title)
 
     gboolean wrap = prefs_get_boolean(PREF_ROSTER_WRAP);
 
-    wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-    win_sub_print(layout->subwin, header->str, FALSE, wrap, 1);
-    wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+    if (layout->subwin != NULL) {
+        wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+        win_sub_print(layout->subwin, header->str, FALSE, wrap, 1);
+        wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+    }
 
     g_string_free(header, TRUE);
 }
diff --git a/src/ui/window.c b/src/ui/window.c
index 860633de..5a1a90dc 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1863,7 +1863,12 @@ win_sub_print(WINDOW* win, char* msg, gboolean newline, gboolean wrap, int inden
 void
 win_sub_newline_lazy(WINDOW* win)
 {
-    int curx = getcurx(win);
+    int curx;
+
+    if (win == NULL) {
+        return;
+    }
+    curx = getcurx(win);
     if (curx > 0) {
         int cury = getcury(win);
         wmove(win, cury + 1, 0);