From b8a4900393a74864101bf89d50a0d96430d217ad Mon Sep 17 00:00:00 2001 From: "jabber.developer2" Date: Mon, 4 May 2026 18:52:39 +0300 Subject: [PATCH] fix(jid): treat NULL/empty/"(null)" barejid the same as resource --- src/database_flatfile_parser.c | 7 +++++-- src/xmpp/jid.c | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/database_flatfile_parser.c b/src/database_flatfile_parser.c index 91866ee3..063efc8d 100644 --- a/src/database_flatfile_parser.c +++ b/src/database_flatfile_parser.c @@ -465,7 +465,8 @@ ff_write_line(FILE* fp, const char* timestamp, const char* type, const char* enc if (safe_rid) { g_string_append_printf(meta, "|corrects:%s", safe_rid); } - if (to_jid && strlen(to_jid) > 0) { + if (to_jid && strlen(to_jid) > 0 + && g_strcmp0(to_jid, "(null)") != 0) { auto_gchar gchar* safe_to = ff_escape_meta_value(to_jid); g_string_append_printf(meta, "|to:%s", safe_to); } @@ -481,7 +482,9 @@ ff_write_line(FILE* fp, const char* timestamp, const char* type, const char* enc // Build sender — escape ": " in the resource part to prevent // the parser from splitting at the wrong point. - GString* sender = g_string_new(from_jid ? from_jid : "unknown"); + const gboolean from_jid_usable = from_jid && *from_jid + && g_strcmp0(from_jid, "(null)") != 0; + GString* sender = g_string_new(from_jid_usable ? from_jid : "unknown"); if (from_resource && strlen(from_resource) > 0 && g_strcmp0(from_resource, "(null)") != 0) { // Escape backslash and colon-space in resource diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c index 4699ad30..aab8cf51 100644 --- a/src/xmpp/jid.c +++ b/src/xmpp/jid.c @@ -113,7 +113,12 @@ jid_create_from_bare_and_resource(const char* const barejid, const char* const r { // NULL, empty, or the literal "(null)" (legacy artefact from earlier // builds where g_strdup_printf("%s", NULL) leaked the glibc placeholder - // into stored resourceparts) all mean "no resource" — return a bare jid. + // into stored data) all mean "no value" for either part. With no usable + // bare jid there is nothing to construct; with no usable resource we + // return the bare jid alone. + if (!barejid || !*barejid || g_strcmp0(barejid, "(null)") == 0) { + return NULL; + } if (!resource || !*resource || g_strcmp0(resource, "(null)") == 0) { return jid_create(barejid); }