merge: sync upstream profanity-im/profanity
All checks were successful
CI Code / Check spelling (push) Successful in 18s
CI Code / Check coding style (push) Successful in 34s
CI Code / Code Coverage (push) Successful in 2m36s
CI Code / Linux (debian) (push) Successful in 4m41s
CI Code / Linux (ubuntu) (push) Successful in 4m52s
CI Code / Linux (arch) (push) Successful in 5m40s

Sync with upstream profanity-im/profanity.

Major upstream changes incorporated:

Memory management
  - Replace malloc+memset with g_new0 throughout codebase
  - Adopt auto_gchar / auto_gcharv / auto_gerror / auto_jid cleanup macros
  - Replace free() with g_free() for GAlloc'd memory

Editor rewrite
  - Remove pthread-based async editor; use GChildWatch callback API
  - New launch_editor(initial_content, callback, user_data) interface
  - Proper signal handling (SIGINT, SIGTSTP, SIGPIPE reset in child)
  - ui_suspend()/ui_resume() integration for TTY management

OMEMO improvements
  - Dual backend support: libsignal-protocol-c and libomemo-c
  - Proper pre-key removal after use (XEP-0384 compliance)
  - Automatic pre-key regeneration when store drops below threshold
  - New functions: omemo_is_device_active(), omemo_is_jid_trusted()
  - omemo_get_jid_untrusted_fingerprints() for better error messages
  - Fingerprint notifications on new device identity discovery
  - Deterministic pre-key ID generation tracking max_pre_key_id
  - omemo_trust_changed() UI updates on trust state changes

JID validation
  - RFC 6122-compliant validation in jid_is_valid()
  - Character-level checks (RFC 6122 forbidden chars: & ' / : < > @)
  - Length limits: 1023 per component, 3071 total
  - New jid_is_valid_user_jid() for user vs. service JID distinction

Database
  - Schema migration v3: UNIQUE constraint on archive_id for deduplication
  - Triggers for corrected message tracking (replaces_db_id / replaced_by_db_id)
  - db_history_result_t return type, _truncate_datetime_suffix()

UI / console
  - win_warn_needed() / win_warn_sent() warning deduplication hash table
  - PAD_MIN_HEIGHT dynamic pad sizing with PAD_THRESHOLD auto-cleanup
  - Spellcheck integration in input field with Unicode word detection
  - cons_spellcheck_setting() for /settings ui output
  - /[command]? shortcut for command help

Account config
  - Account name sanitization for GKeyFile special chars ([ ] = # \n \r)
  - Replace popen() with g_spawn_sync() for eval_password
  - TLS policy: add "direct" option alongside legacy

Connection
  - Port validation with g_assert (0–65535)
  - SHA-256 certificate fingerprint support (XMPP_CERT_PUBKEY_FINGERPRINT_SHA256)
  - "direct" TLS policy alias for legacy SSL

Common utilities
  - str_xml_sanitize() for XML 1.0 illegal character removal
  - string_matches_one_of() with formatted error messages
  - valid_tls_policy_option() helper
  - prof_date_time_format_iso8601() utility
  - Improved strip_arg_quotes() with backslash unescaping
  - prof_occurrences() uses g_slist_prepend + reverse for performance

PGP / OX
  - Proper GPGME resource cleanup with goto-cleanup pattern
  - g_string_free(xmppuri) leak fix in _ox_key_lookup

CSV export
  - Use GString + g_file_set_contents instead of raw write() syscalls

Tests
  - Restructured into subdirectories: command/, config/, xmpp/, ui/, omemo/, otr/, pgp/
  - New test_cmd_ac.c for autocompleter unit tests
  - Updated stubs for new UI suspend/resume functions

License headers
  - Migrate to SPDX-3.0 identifiers (GPL-3.0-or-later WITH OpenSSL-exception)

────────────────────────────────────────────────────
cproof-specific preservations:

  - XEP-0308 LMC: replace_id ?: id logic in message/stanza/omemo
  - Force encryption: cmd_force_encryption, test_forced_encryption
  - CWE-134: format string protection (cons_show("%s", ...))
  - y_start_pos-based paging in window.c
  - db_history_result_t return type, _truncate_datetime_suffix()

Merge-time fixes:

  - common.c: format-security (-Werror) — cons_show(errmsg) → cons_show("%s", errmsg)
  - database.c: null-deref guard — !msg->timestamp → msg && !msg->timestamp
  - console.c: implicit size_t → int cast — (int)(maxlen + 1)
  - tlscerts.c: %d for size_t — %zu

Build system:
  - Kept autotools (Makefile.am, configure.ac); upstream uses Meson
  - Restored deleted files: bootstrap.sh, autogen.sh, ax_valgrind_check.m4, configure-debug
  - Updated Makefile.am test paths for subdirectory structure
  - Added test_cmd_ac, test_forced_encryption to test sources

Functional tests:
  - Use cproof version; upstream requires stbbr_for_xmlns from updated stabber
  - Not yet available in devs/stabber fork

Closes #64

Merge author: jabber.developer2
Commits authors:
 Michael Vetter <jubalh@iodoru.org>
& Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
2026-05-26 17:48:14 +00:00
parent 3b673150b4
commit 72f4f186da
303 changed files with 10658 additions and 9857 deletions

View File

@@ -4,33 +4,7 @@
*
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
*/
#include "config.h"
@@ -41,75 +15,163 @@
#include <glib.h>
#include "common.h"
#include "log.h"
#include "xmpp/jid.h"
#define JID_MAX_PART_LEN 1023
#define JID_MAX_TOTAL_LEN 3071
static gboolean
_is_invalid_local_char(gunichar c)
{
// RFC 6122: " & ' / : < > @
// Also space is forbidden.
return (c == ' ' || c == '"' || c == '&' || c == '\'' || c == '/' || c == ':' || c == '<' || c == '>' || c == '@');
}
Jid*
jid_create(const gchar* const str)
{
Jid* result = NULL;
if (!jid_is_valid(str)) {
log_debug("[JID] invalid JID: '%s'", str ?: "(null)");
return NULL;
}
/* if str is NULL g_strdup returns NULL */
gchar* trimmed = g_strdup(str);
if (trimmed == NULL) {
return NULL;
}
if (strlen(trimmed) == 0) {
g_free(trimmed);
return NULL;
}
if (g_str_has_prefix(trimmed, "/") || g_str_has_prefix(trimmed, "@")) {
g_free(trimmed);
return NULL;
}
if (!g_utf8_validate(trimmed, -1, NULL)) {
g_free(trimmed);
return NULL;
}
result = malloc(sizeof(struct jid_t));
result->str = NULL;
result->localpart = NULL;
result->domainpart = NULL;
result->resourcepart = NULL;
result->barejid = NULL;
result->fulljid = NULL;
Jid* result = g_new0(Jid, 1);
result->refcnt = 1;
result->str = trimmed;
gchar* atp = g_utf8_strchr(trimmed, -1, '@');
gchar* slashp = g_utf8_strchr(trimmed, -1, '/');
gchar* domain_start = trimmed;
auto_gchar gchar* bare = NULL;
if (slashp) {
if (strlen(slashp + 1) > 0) {
result->resourcepart = g_strdup(slashp + 1);
result->fulljid = g_strdup(trimmed);
}
bare = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, slashp));
} else {
bare = g_strdup(trimmed);
}
gchar* atp = g_utf8_strchr(bare, -1, '@');
gchar* domain_start = bare;
if (atp) {
result->localpart = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, atp));
if (g_utf8_pointer_to_offset(bare, atp) > 0) {
result->localpart = g_utf8_substring(bare, 0, g_utf8_pointer_to_offset(bare, atp));
}
domain_start = atp + 1;
}
if (slashp) {
result->resourcepart = g_strdup(slashp + 1);
result->domainpart = g_utf8_substring(domain_start, 0, g_utf8_pointer_to_offset(domain_start, slashp));
auto_gchar gchar* barejidraw = g_utf8_substring(trimmed, 0, g_utf8_pointer_to_offset(trimmed, slashp));
result->barejid = g_utf8_strdown(barejidraw, -1);
result->fulljid = g_strdup(trimmed);
} else {
if (strlen(domain_start) > 0) {
result->domainpart = g_strdup(domain_start);
result->barejid = g_utf8_strdown(trimmed, -1);
}
if (result->domainpart == NULL) {
jid_destroy(result);
return NULL;
}
result->str = trimmed;
result->barejid = g_utf8_strdown(bare, -1);
return result;
}
gboolean
jid_is_valid(const gchar* const str)
{
if (str == NULL) {
return FALSE;
}
size_t total_len = strlen(str);
if (total_len == 0 || total_len > JID_MAX_TOTAL_LEN) {
return FALSE;
}
if (!g_utf8_validate(str, -1, NULL)) {
return FALSE;
}
const gchar* slash = g_utf8_strchr(str, -1, '/');
const gchar* at = NULL;
// Find the first '@' that is NOT in the resourcepart
// and ensure there is at most one '@' in the bare JID
const gchar* p = str;
while (*p && (!slash || p < slash)) {
if (g_utf8_get_char(p) == '@') {
if (at == NULL) {
at = p;
} else {
// More than one '@' in bare JID
return FALSE;
}
}
p = g_utf8_next_char(p);
}
const gchar* domain_start = str;
size_t domain_len = 0;
// Localpart validation
if (at) {
size_t local_len = at - str;
if (local_len == 0 || local_len > JID_MAX_PART_LEN) {
return FALSE;
}
const gchar* lp = str;
while (lp < at) {
gunichar c = g_utf8_get_char(lp);
if (_is_invalid_local_char(c)) {
return FALSE;
}
lp = g_utf8_next_char(lp);
}
domain_start = at + 1;
}
// Resourcepart validation if present
if (slash) {
domain_len = slash - domain_start;
size_t resource_len = strlen(slash + 1);
if (resource_len > JID_MAX_PART_LEN) {
return FALSE;
}
} else {
domain_len = strlen(domain_start);
}
// Domainpart validation
if (domain_len == 0 || domain_len > JID_MAX_PART_LEN) {
return FALSE;
}
return TRUE;
}
gboolean
jid_is_valid_user_jid(const gchar* const str)
{
if (!jid_is_valid(str)) {
return FALSE;
}
const gchar* slash = g_utf8_strchr(str, -1, '/');
const gchar* at = g_utf8_strchr(str, -1, '@');
// A user JID must have an '@' before any '/'
if (at && (!slash || at < slash)) {
return TRUE;
}
return FALSE;
}
Jid*
jid_create_from_bare_and_resource(const char* const barejid, const char* const resource)
jid_create_from_bare_and_resource(const gchar* const barejid, const gchar* const resource)
{
// NULL, empty, or the literal "(null)" (legacy artefact from earlier
// builds where g_strdup_printf("%s", NULL) leaked the glibc placeholder
@@ -122,7 +184,7 @@ jid_create_from_bare_and_resource(const char* const barejid, const char* const r
if (!resource || !*resource || g_strcmp0(resource, "(null)") == 0) {
return jid_create(barejid);
}
auto_char char* jid = create_fulljid(barejid, resource);
auto_gchar gchar* jid = create_fulljid(barejid, resource);
return jid_create(jid);
}
@@ -157,7 +219,7 @@ jid_destroy(Jid* jid)
g_free(jid->resourcepart);
g_free(jid->barejid);
g_free(jid->fulljid);
free(jid);
g_free(jid);
}
gboolean
@@ -171,11 +233,15 @@ jid_is_valid_room_form(Jid* jid)
* barejid/resourcepart
* Will return a newly created string that must be freed by the caller
*/
char*
create_fulljid(const char* const barejid, const char* const resource)
gchar*
create_fulljid(const gchar* const barejid, const gchar* const resource)
{
auto_gchar gchar* barejidlower = g_utf8_strdown(barejid, -1);
return g_strdup_printf("%s/%s", barejidlower, resource);
if (resource && strlen(resource) > 0) {
return g_strdup_printf("%s/%s", barejidlower, resource);
} else {
return g_strdup(barejidlower);
}
}
/*
@@ -183,11 +249,11 @@ create_fulljid(const char* const barejid, const char* const resource)
* Full JID = "test@conference.server/person"
* returns "person"
*/
char*
get_nick_from_full_jid(const char* const full_room_jid)
gchar*
get_nick_from_full_jid(const gchar* const full_room_jid)
{
auto_gcharv gchar** tokens = g_strsplit(full_room_jid, "/", 0);
char* nick_part = NULL;
gchar* nick_part = NULL;
if (tokens) {
if (tokens[0] && tokens[1]) {
@@ -201,7 +267,7 @@ get_nick_from_full_jid(const char* const full_room_jid)
/*
* get the fulljid, fall back to the barejid
*/
const char*
const gchar*
jid_fulljid_or_barejid(Jid* jid)
{
if (jid->fulljid) {
@@ -214,7 +280,7 @@ jid_fulljid_or_barejid(Jid* jid)
gchar*
jid_random_resource(void)
{
auto_char char* rand = get_random_string(4);
auto_gchar gchar* rand = get_random_string(4);
gchar* result = g_strdup_printf("profanity.%s", rand);