diff --git a/src/database_flatfile_parser.c b/src/database_flatfile_parser.c index 650d5790..91866ee3 100644 --- a/src/database_flatfile_parser.c +++ b/src/database_flatfile_parser.c @@ -469,7 +469,8 @@ ff_write_line(FILE* fp, const char* timestamp, const char* type, const char* enc auto_gchar gchar* safe_to = ff_escape_meta_value(to_jid); g_string_append_printf(meta, "|to:%s", safe_to); } - if (to_resource && strlen(to_resource) > 0) { + if (to_resource && strlen(to_resource) > 0 + && g_strcmp0(to_resource, "(null)") != 0) { auto_gchar gchar* safe_tores = ff_escape_meta_value(to_resource); g_string_append_printf(meta, "|to_res:%s", safe_tores); } @@ -481,7 +482,8 @@ 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"); - if (from_resource && strlen(from_resource) > 0) { + if (from_resource && strlen(from_resource) > 0 + && g_strcmp0(from_resource, "(null)") != 0) { // Escape backslash and colon-space in resource GString* safe_res = g_string_sized_new(strlen(from_resource)); for (const char* p = from_resource; *p; p++) { diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c index 6b5bb62c..4699ad30 100644 --- a/src/xmpp/jid.c +++ b/src/xmpp/jid.c @@ -111,6 +111,12 @@ jid_create(const gchar* const str) Jid* jid_create_from_bare_and_resource(const char* const barejid, const char* const resource) { + // 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. + if (!resource || !*resource || g_strcmp0(resource, "(null)") == 0) { + return jid_create(barejid); + } auto_char char* jid = create_fulljid(barejid, resource); return jid_create(jid); }