From d3d7c328b42325b87d847f705a0253b7bf05ab0b Mon Sep 17 00:00:00 2001 From: Jabber Developer Date: Fri, 22 May 2026 18:27:54 +0000 Subject: [PATCH] fix: address config injection and SIGCHLD handling - Sanitize account names to prevent GKeyFile config injection by blocking special characters like #, \n, and \r. - Ensure GLib's SIGCHLD handler is initialized before forking external editors to prevent zombie processes. - Add missing error check for OMEMO random key generation. - Replace hardcoded console tab ID with a named constant. - Log invalid JIDs safely to prevent potential null pointer issues. --- src/config/accounts.c | 3 ++- src/omemo/omemo.c | 4 ++++ src/tools/editor.c | 6 ++++++ src/ui/statusbar.c | 4 +++- src/xmpp/jid.c | 1 + 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/config/accounts.c b/src/config/accounts.c index 3938f4a3..af6b901d 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -43,7 +43,8 @@ _sanitize_account_name(const char* const name) gchar* sanitized = g_strdup(name); gchar* p = sanitized; while (*p) { - if (*p == '[' || *p == ']' || *p == '=') { + // GKeyFile special characters: [ ] = # \n \r + if (*p == '[' || *p == ']' || *p == '=' || *p == '#' || *p == '\n' || *p == '\r') { *p = '_'; } p++; diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index b018158b..ff642e7c 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -806,6 +806,10 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_ key_tag = gcry_malloc_secure(AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH); key = gcry_random_bytes_secure(AES128_GCM_KEY_LENGTH + AES128_GCM_IV_LENGTH, GCRY_VERY_STRONG_RANDOM); + if (!key) { + log_error("[OMEMO][SEND] cannot generate random key/IV"); + goto out; + } iv = key + AES128_GCM_KEY_LENGTH; res = aes128gcm_encrypt(ciphertext, &ciphertext_len, tag, &tag_len, (const unsigned char* const)message, strlen(message), iv, key); diff --git a/src/tools/editor.c b/src/tools/editor.c index 98b0be71..85690022 100644 --- a/src/tools/editor.c +++ b/src/tools/editor.c @@ -121,6 +121,12 @@ launch_editor(gchar* initial_content, void (*callback)(gchar* content, void* dat ui_suspend(); + // Ensure GLib's SIGCHLD handler is installed before forking to prevent + // zombie children if the editor is launched before the main loop starts. + GMainContext* main_ctx = g_main_context_default(); + g_main_context_acquire(main_ctx); + g_main_context_release(main_ctx); + pid_t pid = fork(); if (pid == -1) { log_error("[Editor] Failed to fork: %s", strerror(errno)); diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 04f0eb2e..da5bb543 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -55,6 +55,8 @@ static GTimeZone* tz; static StatusBar* statusbar; static WINDOW* statusbar_win; +#define CONSOLE_TAB_ID 10 // Console tab ID in status bar hash table + void _get_range_bounds(guint* start, guint* end, gboolean is_static); static guint _status_bar_draw_time(guint pos); static guint _status_bar_draw_maintext(guint pos); @@ -157,7 +159,7 @@ void status_bar_current(guint i) { if (i == 0) { - statusbar->current_tab = 10; + statusbar->current_tab = CONSOLE_TAB_ID; } else { statusbar->current_tab = i; } diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c index 8b7dbbdf..4387a696 100644 --- a/src/xmpp/jid.c +++ b/src/xmpp/jid.c @@ -32,6 +32,7 @@ Jid* jid_create(const gchar* const str) { if (!jid_is_valid(str)) { + log_debug("[JID] invalid JID: '%s'", str ?: "(null)"); return NULL; }