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"
@@ -234,6 +208,11 @@ _iq_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const us
blocked_set_handler(stanza);
}
xmpp_stanza_t* reporting = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_REPORTING);
if (reporting && (g_strcmp0(type, STANZA_TYPE_SET) == 0)) {
reporting_set_handler(stanza);
}
const char* id = xmpp_stanza_get_id(stanza);
if (id) {
ProfIqHandler* handler = g_hash_table_lookup(id_handlers, id);
@@ -248,6 +227,12 @@ _iq_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const us
return 1;
}
static void
_xmpp_stanza_release_destroy_notify(gpointer data)
{
xmpp_stanza_release((xmpp_stanza_t*)data);
}
void
iq_handlers_init(void)
{
@@ -264,7 +249,7 @@ iq_handlers_init(void)
iq_handlers_clear();
id_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_iq_id_handler_free);
rooms_cache = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)xmpp_stanza_release);
rooms_cache = g_hash_table_new_full(g_str_hash, g_str_equal, free, _xmpp_stanza_release_destroy_notify);
}
struct iq_win_finder
@@ -302,7 +287,7 @@ _free_late_delivery_userdata(LateDeliveryUserdata* d)
void
iq_handlers_remove_win(ProfWin* window)
{
log_debug("Remove window %p of type %d", window, window ? window->type : -1);
log_debug("Remove window %p of type %d", window, window ? window->type : (win_type_t)-1);
if (!window)
return;
GSList *cur = late_delivery_windows, *next;
@@ -358,14 +343,19 @@ _iq_id_handler_free(ProfIqHandler* handler)
void
iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata)
{
ProfIqHandler* handler = malloc(sizeof(ProfIqHandler));
if (handler) {
handler->func = func;
handler->free_func = free_func;
handler->userdata = userdata;
g_hash_table_insert(id_handlers, strdup(id), handler);
if (id == NULL) {
if (free_func) {
free_func(userdata);
}
return;
}
ProfIqHandler* handler = g_new0(ProfIqHandler, 1);
handler->func = func;
handler->free_func = free_func;
handler->userdata = userdata;
g_hash_table_insert(id_handlers, strdup(id), handler);
}
void
@@ -394,7 +384,7 @@ iq_autoping_check(void)
}
gdouble elapsed = g_timer_elapsed(autoping_time, NULL);
unsigned long seconds_elapsed = elapsed * 1.0;
gint seconds_elapsed = (gint)elapsed;
gint timeout = prefs_get_autoping_timeout();
if (timeout > 0 && seconds_elapsed >= timeout) {
cons_show("Autoping response timed out after %u seconds.", timeout);
@@ -545,7 +535,7 @@ iq_room_info_request(const char* const room, gboolean display_result)
auto_char char* id = connection_create_stanza_id();
xmpp_stanza_t* iq = stanza_create_disco_info_iq(ctx, id, room, NULL);
ProfRoomInfoData* cb_data = malloc(sizeof(ProfRoomInfoData));
ProfRoomInfoData* cb_data = g_new0(ProfRoomInfoData, 1);
if (cb_data) {
cb_data->room = strdup(room);
cb_data->display = display_result;
@@ -729,7 +719,7 @@ iq_room_affiliation_list(const char* const room, char* affiliation, bool show_ui
const char* id = xmpp_stanza_get_id(iq);
ProfAffiliationList* affiliation_list = malloc(sizeof(ProfAffiliationList));
ProfAffiliationList* affiliation_list = g_new0(ProfAffiliationList, 1);
if (affiliation_list) {
affiliation_list->affiliation = strdup(affiliation);
affiliation_list->show_ui_message = show_ui_message;
@@ -763,7 +753,7 @@ iq_room_affiliation_set(const char* const room, const char* const jid, char* aff
const char* id = xmpp_stanza_get_id(iq);
ProfPrivilegeSet* affiliation_set = malloc(sizeof(struct privilege_set_t));
ProfPrivilegeSet* affiliation_set = g_new0(struct privilege_set_t, 1);
if (affiliation_set) {
affiliation_set->item = strdup(jid);
affiliation_set->privilege = strdup(affiliation);
@@ -784,7 +774,7 @@ iq_room_role_set(const char* const room, const char* const nick, char* role,
const char* id = xmpp_stanza_get_id(iq);
struct privilege_set_t* role_set = malloc(sizeof(ProfPrivilegeSet));
struct privilege_set_t* role_set = g_new0(ProfPrivilegeSet, 1);
if (role_set) {
role_set->item = strdup(nick);
role_set->privilege = strdup(role);
@@ -1148,7 +1138,7 @@ _room_list_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
if (item_name) {
item_name_lower = g_utf8_strdown(item_name, -1);
}
if ((item_jid_lower) && ((glob == NULL) || ((g_pattern_match(glob, strlen(item_jid_lower), item_jid_lower, NULL)) || (item_name_lower && g_pattern_match(glob, strlen(item_name_lower), item_name_lower, NULL))))) {
if ((item_jid_lower) && ((glob == NULL) || ((g_pattern_match(glob, (guint)strlen(item_jid_lower), item_jid_lower, NULL)) || (item_name_lower && g_pattern_match(glob, (guint)strlen(item_name_lower), item_name_lower, NULL))))) {
if (glob) {
matched = TRUE;
@@ -1327,7 +1317,7 @@ _command_exec_response_handler(xmpp_stanza_t* const stanza, void* const userdata
const char* sessionid = xmpp_stanza_get_attribute(cmd, "sessionid");
DataForm* form = form_create(x);
CommandConfigData* data = malloc(sizeof(CommandConfigData));
CommandConfigData* data = g_new0(CommandConfigData, 1);
if (sessionid == NULL) {
data->sessionid = NULL;
} else {
@@ -1404,7 +1394,7 @@ _manual_pong_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
GDateTime* now = g_date_time_new_now_local();
GTimeSpan elapsed = g_date_time_difference(now, sent);
int elapsed_millis = elapsed / 1000;
int elapsed_millis = (int)(elapsed / 1000);
g_date_time_unref(now);
@@ -1791,7 +1781,7 @@ _last_activity_get_handler(xmpp_stanza_t* const stanza)
}
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
int idls_secs = ui_get_idle_time() / 1000;
int idls_secs = (int)(ui_get_idle_time() / 1000);
char str[50];
sprintf(str, "%d", idls_secs);
@@ -2211,7 +2201,7 @@ _room_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdata
const char* category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY);
if (name || category || type) {
DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t));
DiscoIdentity* identity = g_new0(struct disco_identity_t, 1);
if (identity) {
if (name) {
@@ -2356,7 +2346,7 @@ _disco_info_response_id_handler(xmpp_stanza_t* const stanza, void* const userdat
const char* category = xmpp_stanza_get_attribute(child, STANZA_ATTR_CATEGORY);
if (name || category || child_type) {
DiscoIdentity* identity = malloc(sizeof(struct disco_identity_t));
DiscoIdentity* identity = g_new0(struct disco_identity_t, 1);
if (identity) {
if (name) {
@@ -2538,7 +2528,7 @@ _disco_items_result_handler(xmpp_stanza_t* const stanza)
if (stanza_name && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) {
const char* item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
if (item_jid) {
DiscoItem* item = malloc(sizeof(struct disco_item_t));
DiscoItem* item = g_new0(struct disco_item_t, 1);
if (item) {
item->jid = strdup(item_jid);
const char* item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
@@ -2649,10 +2639,13 @@ iq_mam_request_older(ProfChatWin* win)
auto_gchar gchar* enddate = NULL;
// If first message found
if (first_msg->timestamp) {
if (first_msg && first_msg->timestamp) {
firstid = first_msg->stanzaid;
enddate = g_date_time_format(first_msg->timestamp, mam_timestamp_format_string);
} else {
if (first_msg) {
message_free(first_msg);
}
return;
}
@@ -2686,8 +2679,10 @@ _iq_mam_request(ProfChatWin* win, GDateTime* startdate, GDateTime* enddate)
if (connection_supports(XMPP_FEATURE_MAM2) == FALSE) {
log_warning("Server doesn't advertise %s feature.", XMPP_FEATURE_MAM2);
cons_show_error("Server doesn't support MAM (%s).", XMPP_FEATURE_MAM2);
g_date_time_unref(startdate);
g_date_time_unref(enddate);
if (startdate)
g_date_time_unref(startdate);
if (enddate)
g_date_time_unref(enddate);
return;
}
@@ -2715,7 +2710,7 @@ _iq_mam_request(ProfChatWin* win, GDateTime* startdate, GDateTime* enddate)
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, win->barejid, startdate_str, enddate_str, firstid, NULL);
MamRsmUserdata* data = malloc(sizeof(MamRsmUserdata));
MamRsmUserdata* data = g_new0(MamRsmUserdata, 1);
if (data) {
data->start_datestr = startdate_str;
data->end_datestr = enddate_str;
@@ -2736,12 +2731,16 @@ void
iq_mam_request(ProfChatWin* win, GDateTime* enddate)
{
ProfMessage* last_msg = log_database_get_limits_info(win->barejid, TRUE);
GDateTime* startdate = g_date_time_ref(last_msg->timestamp);
message_free(last_msg);
GDateTime* startdate = NULL;
if (last_msg) {
if (last_msg->timestamp)
startdate = g_date_time_ref(last_msg->timestamp);
message_free(last_msg);
}
// Save request for later if disco items haven't been received yet
if (!received_disco_items) {
LateDeliveryUserdata* cur_del_data = malloc(sizeof(LateDeliveryUserdata));
LateDeliveryUserdata* cur_del_data = g_new0(LateDeliveryUserdata, 1);
cur_del_data->win = win;
cur_del_data->enddate = enddate;
cur_del_data->startdate = startdate;
@@ -2830,7 +2829,7 @@ _mam_rsm_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
}
xmpp_stanza_t* iq = stanza_create_mam_iq(ctx, data->barejid, data->start_datestr, NULL, firstid, NULL);
MamRsmUserdata* ndata = malloc(sizeof(*ndata));
MamRsmUserdata* ndata = g_new0(MamRsmUserdata, 1);
*ndata = *data;
if (data->end_datestr)
ndata->end_datestr = strdup(data->end_datestr);