From be42ffcee95214215ca5e2412083da004ac7332f Mon Sep 17 00:00:00 2001 From: John Hernandez <129467592+H3rnand3zzz@users.noreply.github.com> Date: Sun, 15 Oct 2023 23:23:01 +0200 Subject: [PATCH 1/2] Fix crash on quick `/reconnect now` usage (double free) Check connection state before reconnection. Fix #1894 https://github.com/profanity-im/profanity/issues/1894 --- src/command/cmd_funcs.c | 1 - src/event/client_events.c | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index eefe5a57..749771df 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -6467,7 +6467,6 @@ cmd_reconnect(ProfWin* window, const char* const command, gchar** args) int intval = 0; auto_char char* err_msg = NULL; if (g_strcmp0(value, "now") == 0) { - cons_show("Reconnecting now."); cl_ev_reconnect(); } else if (strtoi_range(value, &intval, 0, INT_MAX, &err_msg)) { prefs_set_reconnect(intval); diff --git a/src/event/client_events.c b/src/event/client_events.c index e8620234..bccedc97 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -98,7 +98,14 @@ cl_ev_disconnect(void) void cl_ev_reconnect(void) { - if (connection_get_status() != JABBER_DISCONNECTED) { + jabber_conn_status_t conn_status = connection_get_status(); + if (conn_status == JABBER_CONNECTING) { + cons_show_error("Reconnection aborted: Connection attempt is already in progress"); + return; + } + + cons_show("Reconnecting now."); + if (conn_status != JABBER_DISCONNECTED && conn_status != JABBER_DISCONNECTING) { connection_disconnect(); ev_disconnect_cleanup(); // on intentional disconnect reset the counter From 3838e5a98231fc2ea886661a379acb038f91c55f Mon Sep 17 00:00:00 2001 From: John Hernandez <129467592+H3rnand3zzz@users.noreply.github.com> Date: Sun, 15 Oct 2023 23:24:13 +0200 Subject: [PATCH 2/2] Fix crash on reconnection in the chat window Profanity tries to access the nickname from the roster, but roster is being cleaned already, thus leading to use-after-free. Fix #1894 https://github.com/profanity-im/profanity/issues/1894 --- src/ui/window.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/window.c b/src/ui/window.c index f75e7d06..730859d2 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -312,7 +312,10 @@ win_get_title(ProfWin* window) { const ProfChatWin* chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); - const PContact contact = roster_get_contact(chatwin->barejid); + PContact contact = NULL; + if (roster_exists()) { + contact = roster_get_contact(chatwin->barejid); + } if (!contact) { return g_strdup(chatwin->barejid); }