From 62e98dee74096a88447237a52a7ac0cf7642b45d Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 12 Jul 2023 13:58:03 +0200 Subject: [PATCH] Fix crash when using NetBSD curses implementation Thanks to @alarixnia fot the patch and bugreport. ``` Forwarding a bug reported using the NetBSD bug tracker ("Profanity crashes at login"): http://gnats.netbsd.org/57050 The code in question here handles messages by people not in the user's contact list, and what is probably happening is that the XMPP server is sending such a message before profanity has set up its window layout. Setting roster.unsubscribed=false indeed makes profanity start without crashing, and the attached patch bails out early in the problematic code path if layout->subwin is NULL (Adrian verified for me that either of the two makes profanity work for him again). But I am not familiar enough with the profanity code to say if this has any issues. Profanity compiled with ncurses doesn't crash because ncurses's wattron() has a guard against the user passing null pointers, but the X/Open curses library standard doesn't have this guarantee and there's no guard in the NetBSD curses implementation. ``` Fix https://github.com/profanity-im/profanity/issues/1769 --- src/ui/rosterwin.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c index e2b0f822..a2c7da7e 100644 --- a/src/ui/rosterwin.c +++ b/src/ui/rosterwin.c @@ -98,9 +98,11 @@ rosterwin_roster(void) ProfLayoutSplit* layout = (ProfLayoutSplit*)console->layout; assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK); - if (layout->subwin != NULL) { - werase(layout->subwin); + if (layout->subwin == NULL) { + return; } + + werase(layout->subwin); auto_gchar gchar* roomspos = prefs_get_string(PREF_ROSTER_ROOMS_POS); if (prefs_get_boolean(PREF_ROSTER_ROOMS) && (g_strcmp0(roomspos, "first") == 0)) {