Compare commits
13 Commits
merge-impr
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
| f63bf57872 | |||
| f16b26bd6d | |||
| a4e6419faf | |||
| 7eb9668068 | |||
| 7404e7092a | |||
| 62361676fe | |||
|
5b45b35b3e
|
|||
|
57d79ecf9c
|
|||
|
bfd7064a40
|
|||
|
3f6b8f69fd
|
|||
|
a04a8948e1
|
|||
|
c1093db090
|
|||
|
72f4f186da
|
44
configure.ac
44
configure.ac
@@ -71,6 +71,10 @@ AC_ARG_ENABLE([omemo-qrcode],
|
||||
[AS_HELP_STRING([--enable-omemo-qrcode], [enable ability to display omemo qr code])])
|
||||
AC_ARG_ENABLE([coverage],
|
||||
[AS_HELP_STRING([--enable-coverage], [enable code coverage analysis])])
|
||||
AC_ARG_ENABLE([sanitizers],
|
||||
[AS_HELP_STRING([--enable-sanitizers], [enable AddressSanitizer + UndefinedBehaviorSanitizer + unsigned-integer-overflow])])
|
||||
AC_ARG_ENABLE([hardening],
|
||||
[AS_HELP_STRING([--enable-hardening], [enable extra hardening warnings (e.g. -Wnull-dereference) that may produce false positives under -O2])])
|
||||
|
||||
m4_include([m4/ax_valgrind_check.m4])
|
||||
AX_VALGRIND_DFLT([drd], [off])
|
||||
@@ -395,7 +399,7 @@ AC_SUBST([FORKPTY_LIB])
|
||||
|
||||
## Default parameters
|
||||
AM_CFLAGS="$AM_CFLAGS -Wall -Wextra -Wformat=2 -Wno-format-zero-length"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wno-deprecated-declarations -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare -Wno-cast-function-type"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wno-deprecated-declarations -Wno-unused-parameter -Wno-missing-field-initializers -Wno-cast-function-type"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wpointer-arith"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wimplicit-function-declaration"
|
||||
AM_CFLAGS="$AM_CFLAGS -Wundef"
|
||||
@@ -406,7 +410,8 @@ AM_CFLAGS="$AM_CFLAGS -std=gnu99 -ggdb3"
|
||||
# GCC-specific warnings (not supported by clang) — test each one
|
||||
saved_CFLAGS="$CFLAGS"
|
||||
for _flag in -Wlogical-op -Wduplicated-cond -Wduplicated-branches \
|
||||
-Wstringop-overflow -Warray-bounds=2 -Walloc-zero; do
|
||||
-Wstringop-overflow -Warray-bounds=2 -Walloc-zero \
|
||||
-Wsign-compare; do
|
||||
AC_MSG_CHECKING([whether $CC supports $_flag])
|
||||
CFLAGS="$saved_CFLAGS $_flag -Werror"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
|
||||
@@ -433,11 +438,46 @@ AS_IF([test "x$enable_coverage" = xyes],
|
||||
AM_LDFLAGS="$AM_LDFLAGS --coverage"
|
||||
AC_MSG_NOTICE([Code coverage analysis enabled])])
|
||||
|
||||
AS_IF([test "x$enable_sanitizers" = xyes],
|
||||
[SAN_FLAGS="-fsanitize=address,undefined"
|
||||
saved_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$saved_CFLAGS -fsanitize=unsigned-integer-overflow -Werror"
|
||||
AC_MSG_CHECKING([whether $CC supports -fsanitize=unsigned-integer-overflow])
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
|
||||
[AC_MSG_RESULT([yes]); SAN_FLAGS="$SAN_FLAGS,unsigned-integer-overflow"],
|
||||
[AC_MSG_RESULT([no])])
|
||||
CFLAGS="$saved_CFLAGS"
|
||||
AM_CFLAGS="$AM_CFLAGS $SAN_FLAGS -fno-sanitize-recover=all -fno-omit-frame-pointer"
|
||||
AM_LDFLAGS="$AM_LDFLAGS -fsanitize=address,undefined"
|
||||
AC_MSG_NOTICE([Sanitizers enabled: $SAN_FLAGS])])
|
||||
|
||||
AS_IF([test "x$enable_hardening" = xyes],
|
||||
[saved_CFLAGS="$CFLAGS"
|
||||
for _flag in -Wnull-dereference; do
|
||||
AC_MSG_CHECKING([whether $CC supports $_flag])
|
||||
CFLAGS="$saved_CFLAGS $_flag -Werror"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
|
||||
[AC_MSG_RESULT([yes]); AM_CFLAGS="$AM_CFLAGS $_flag"],
|
||||
[AC_MSG_RESULT([no])])
|
||||
done
|
||||
CFLAGS="$saved_CFLAGS"
|
||||
AC_MSG_NOTICE([Extra hardening warnings enabled])])
|
||||
|
||||
# Skip _FORTIFY_SOURCE=2 if env already set one (Pikaur/makepkg) or under coverage -O0 (FORTIFY needs -O>0).
|
||||
AS_IF([test "x$enable_coverage" != xyes],
|
||||
[AS_CASE([" ${CPPFLAGS} ${CFLAGS} "],
|
||||
[*_FORTIFY_SOURCE=*], [AC_MSG_NOTICE([_FORTIFY_SOURCE preset from environment, leaving as-is])],
|
||||
[AM_CFLAGS="$AM_CFLAGS -D_FORTIFY_SOURCE=2"])])
|
||||
|
||||
AS_IF([test "x$PACKAGE_STATUS" = xdevelopment],
|
||||
[AM_CFLAGS="$AM_CFLAGS -Wunused -Werror"])
|
||||
AS_IF([test "x$PLATFORM" = xosx],
|
||||
[AM_CFLAGS="$AM_CFLAGS -Qunused-arguments"])
|
||||
|
||||
# Treat glib/gio headers as system to keep their macros out of our -W* set.
|
||||
glib_CFLAGS=$(echo "$glib_CFLAGS" | sed 's/-I/-isystem /g')
|
||||
gio_CFLAGS=$(echo "$gio_CFLAGS" | sed 's/-I/-isystem /g')
|
||||
|
||||
AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS $glib_CFLAGS $gio_CFLAGS $curl_CFLAGS ${SQLITE_CFLAGS}"
|
||||
AM_CFLAGS="$AM_CFLAGS $libnotify_CFLAGS ${GTK_CFLAGS} $python_CFLAGS"
|
||||
AM_CFLAGS="$AM_CFLAGS -DTHEMES_PATH=\"\\\"$THEMES_PATH\\\"\" -DICONS_PATH=\"\\\"$ICONS_PATH\\\"\" -DGLOBAL_PYTHON_PLUGINS_PATH=\"\\\"$GLOBAL_PYTHON_PLUGINS_PATH\\\"\" -DGLOBAL_C_PLUGINS_PATH=\"\\\"$GLOBAL_C_PLUGINS_PATH\\\"\""
|
||||
|
||||
@@ -2638,7 +2638,8 @@ static const struct cmd_t command_defs[] = {
|
||||
CMD_DESC(
|
||||
"Spawn external editor to edit message. "
|
||||
"After editing the inputline may appear empty. Press enter to send the text anyways. "
|
||||
"Use /executable to set your favourite editor." )
|
||||
"Use /executable to set your favourite editor. "
|
||||
"Ctrl-Z in the editor aborts the session and returns to Profanity." )
|
||||
},
|
||||
|
||||
{ CMD_PREAMBLE("/correct-editor",
|
||||
|
||||
@@ -10063,8 +10063,14 @@ cmd_vcard_remove(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
|
||||
if (args[1]) {
|
||||
vcard_user_remove_element(atoi(args[1]));
|
||||
cons_show("Removed element at index %d", atoi(args[1]));
|
||||
int index;
|
||||
auto_gchar gchar* err_msg = NULL;
|
||||
if (!strtoi_range(args[1], &index, 0, INT_MAX, &err_msg)) {
|
||||
cons_show_error("%s", err_msg);
|
||||
return TRUE;
|
||||
}
|
||||
vcard_user_remove_element((unsigned int)index);
|
||||
cons_show("Removed element at index %d", index);
|
||||
vcardwin_update();
|
||||
} else {
|
||||
cons_bad_cmd_usage(command);
|
||||
|
||||
40
src/common.c
40
src/common.c
@@ -294,7 +294,7 @@ str_replace(const char* string, const char* substr,
|
||||
wr = newstr;
|
||||
|
||||
while ((tok = strstr(head, substr))) {
|
||||
size_t l = tok - head;
|
||||
size_t l = g_diff_to_gsize(tok, head);
|
||||
memcpy(wr, head, l);
|
||||
wr += l;
|
||||
memcpy(wr, replacement, len_replacement);
|
||||
@@ -309,6 +309,16 @@ str_replace(const char* string, const char* substr,
|
||||
return newstr;
|
||||
}
|
||||
|
||||
gsize
|
||||
g_diff_to_gsize(const void* end, const void* start)
|
||||
{
|
||||
if (end < start) {
|
||||
log_error("g_diff_to_gsize: end < start (%p < %p)", end, start);
|
||||
return 0;
|
||||
}
|
||||
return (gsize)((const char*)end - (const char*)start);
|
||||
}
|
||||
|
||||
gboolean
|
||||
strtoi_range(const char* str, int* saveptr, int min, int max, gchar** err_msg)
|
||||
{
|
||||
@@ -359,9 +369,9 @@ string_matches_one_of(const char* what, const char* is, gboolean is_can_be_null,
|
||||
char errmsg[256] = { 0 };
|
||||
size_t sz = 0;
|
||||
int s = snprintf(errmsg, sizeof(errmsg) - sz, "%s must be one of:", what);
|
||||
if (s < 0 || s + sz >= sizeof(errmsg))
|
||||
if (s < 0 || (size_t)s + sz >= sizeof(errmsg))
|
||||
return ret;
|
||||
sz += s;
|
||||
sz += (size_t)s;
|
||||
|
||||
cur = first;
|
||||
va_start(ap, first);
|
||||
@@ -375,12 +385,12 @@ string_matches_one_of(const char* what, const char* is, gboolean is_can_be_null,
|
||||
errmsg[sz] = '\0';
|
||||
s = snprintf(errmsg + sz, sizeof(errmsg) - sz, " or '%s'.", cur);
|
||||
}
|
||||
if (s < 0 || s + sz >= sizeof(errmsg)) {
|
||||
if (s < 0 || (size_t)s + sz >= sizeof(errmsg)) {
|
||||
log_debug("Error message too long or some other error occurred (%d).", s);
|
||||
s = -1;
|
||||
break;
|
||||
}
|
||||
sz += s;
|
||||
sz += (size_t)s;
|
||||
cur = next;
|
||||
}
|
||||
va_end(ap);
|
||||
@@ -431,7 +441,7 @@ str_xml_sanitize(const char* const str)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GString* sanitized = g_string_new_len(NULL, strlen(str));
|
||||
GString* sanitized = g_string_new_len(NULL, (gssize)strlen(str));
|
||||
const char* curr = str;
|
||||
|
||||
while (*curr != '\0') {
|
||||
@@ -690,7 +700,7 @@ get_file_paths_recursive(const char* path, GSList** contents)
|
||||
}
|
||||
|
||||
gchar*
|
||||
get_random_string(int length)
|
||||
get_random_string(size_t length)
|
||||
{
|
||||
GRand* prng;
|
||||
gchar* rand;
|
||||
@@ -701,7 +711,7 @@ get_random_string(int length)
|
||||
|
||||
prng = g_rand_new();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
rand[i] = alphabet[g_rand_int_range(prng, 0, endrange)];
|
||||
}
|
||||
g_rand_free(prng);
|
||||
@@ -748,17 +758,17 @@ call_external(gchar** argv)
|
||||
*
|
||||
* This function constructs an argument vector (argv) based on the provided template string, replacing placeholders ("%u" and "%p") with the provided URL and filename, respectively.
|
||||
*
|
||||
* @param template The template string with placeholders.
|
||||
* @param url The URL to replace "%u" (or NULL to skip).
|
||||
* @param filename The filename to replace "%p" (or NULL to skip).
|
||||
* @return The constructed argument vector (argv) as a null-terminated array of strings.
|
||||
* @param template_fmt The template string with placeholders.
|
||||
* @param url The URL to replace "%u" (or NULL to skip).
|
||||
* @param filename The filename to replace "%p" (or NULL to skip).
|
||||
* @return The constructed argument vector (argv) as a null-terminated array of strings.
|
||||
*
|
||||
* @note Remember to free the returned argument vector using `auto_gcharv` or `g_strfreev()`.
|
||||
*/
|
||||
gchar**
|
||||
format_call_external_argv(const char* template, const char* url, const char* filename)
|
||||
format_call_external_argv(const char* template_fmt, const char* url, const char* filename)
|
||||
{
|
||||
gchar** argv = g_strsplit(template, " ", 0);
|
||||
gchar** argv = g_strsplit(template_fmt, " ", 0);
|
||||
|
||||
guint num_args = 0;
|
||||
while (argv[num_args]) {
|
||||
@@ -767,7 +777,7 @@ format_call_external_argv(const char* template, const char* url, const char* fil
|
||||
argv[num_args] = g_strdup(url);
|
||||
} else if (0 == g_strcmp0(argv[num_args], "%p") && filename != NULL) {
|
||||
g_free(argv[num_args]);
|
||||
argv[num_args] = strdup(filename);
|
||||
argv[num_args] = g_strdup(filename);
|
||||
}
|
||||
num_args++;
|
||||
}
|
||||
|
||||
@@ -158,6 +158,7 @@ gboolean create_dir(const char* name);
|
||||
gboolean copy_file(const char* const src, const char* const target, const gboolean overwrite_existing);
|
||||
char* str_replace(const char* string, const char* substr, const char* replacement);
|
||||
gboolean strtoi_range(const char* str, int* saveptr, int min, int max, char** err_msg);
|
||||
gsize g_diff_to_gsize(const void* end, const void* start);
|
||||
int utf8_display_len(const char* const str);
|
||||
gchar* str_xml_sanitize(const char* const str);
|
||||
|
||||
@@ -178,10 +179,10 @@ int is_regular_file(const char* path);
|
||||
int is_dir(const char* path);
|
||||
void get_file_paths_recursive(const char* directory, GSList** contents);
|
||||
|
||||
gchar* get_random_string(int length);
|
||||
gchar* get_random_string(size_t length);
|
||||
|
||||
gboolean call_external(gchar** argv);
|
||||
gchar** format_call_external_argv(const char* template, const char* url, const char* filename);
|
||||
gchar** format_call_external_argv(const char* template_fmt, const char* url, const char* filename);
|
||||
|
||||
gchar* unique_filename_from_url(const char* url, const char* path);
|
||||
gchar* get_expanded_path(const char* path);
|
||||
|
||||
@@ -43,8 +43,8 @@ _sanitize_account_name(const char* const name)
|
||||
gchar* sanitized = g_strdup(name);
|
||||
gchar* p = sanitized;
|
||||
while (*p) {
|
||||
// GKeyFile special characters: [ ] = # \n \r
|
||||
if (*p == '[' || *p == ']' || *p == '=' || *p == '#' || *p == '\n' || *p == '\r') {
|
||||
// GKeyFile group header forbids these characters.
|
||||
if (*p == '[' || *p == ']' || *p == '\n' || *p == '\r') {
|
||||
*p = '_';
|
||||
}
|
||||
p++;
|
||||
|
||||
@@ -282,7 +282,7 @@ _export_one_contact(const char* contact)
|
||||
gchar* key = _make_dedup_key(pl->stanza_id, pl->timestamp_str, pl->from_jid, pl->message);
|
||||
g_hash_table_add(seen_keys, key);
|
||||
}
|
||||
int existing_count = g_slist_length(existing);
|
||||
int existing_count = (int)g_slist_length(existing);
|
||||
|
||||
// 2. Query SQLite for this contact — get ALL messages via direct SQL
|
||||
GSList* sqlite_lines = db_sqlite_get_all_chat(contact);
|
||||
@@ -581,7 +581,7 @@ log_database_import_from_flatfile(const gchar* const contact_jid)
|
||||
// Wrap in a transaction for atomicity and performance
|
||||
int contact_imported = 0;
|
||||
int contact_skipped = 0;
|
||||
int total_lines = g_slist_length(ff_lines);
|
||||
int total_lines = (int)g_slist_length(ff_lines);
|
||||
|
||||
db_sqlite_begin_transaction();
|
||||
gboolean import_ok = TRUE;
|
||||
|
||||
@@ -88,7 +88,7 @@ _ff_cache_line_ids(ff_contact_state_t* state, const char* line)
|
||||
return;
|
||||
|
||||
// Split metadata on unescaped '|'
|
||||
auto_gchar gchar* meta_str = g_strndup(bracket + 1, close - bracket - 1);
|
||||
auto_gchar gchar* meta_str = g_strndup(bracket + 1, g_diff_to_gsize(close, bracket + 1));
|
||||
char** parts = ff_split_meta(meta_str);
|
||||
|
||||
char* stanza_id = NULL;
|
||||
@@ -111,9 +111,9 @@ _ff_cache_line_ids(ff_contact_state_t* state, const char* line)
|
||||
const char* sender_start = close + 2;
|
||||
const char* colonspace = ff_find_unescaped_colonspace(sender_start);
|
||||
if (colonspace) {
|
||||
const char* slash = memchr(sender_start, '/', colonspace - sender_start);
|
||||
const char* slash = memchr(sender_start, '/', g_diff_to_gsize(colonspace, sender_start));
|
||||
const char* jid_end = slash ? slash : colonspace;
|
||||
from_jid = g_strndup(sender_start, jid_end - sender_start);
|
||||
from_jid = g_strndup(sender_start, g_diff_to_gsize(jid_end, sender_start));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ _ff_maybe_index_line(ff_contact_state_t* state, const char* buf, off_t pos)
|
||||
if (!space)
|
||||
return;
|
||||
|
||||
auto_gchar gchar* ts_str = g_strndup(buf, space - buf);
|
||||
auto_gchar gchar* ts_str = g_strndup(buf, g_diff_to_gsize(space, buf));
|
||||
GDateTime* dt = g_date_time_new_from_iso8601(ts_str, NULL);
|
||||
if (!dt) {
|
||||
log_warning("flatfile: unparsable timestamp in %s at offset %ld: %s",
|
||||
@@ -771,7 +771,7 @@ _flatfile_get_previous_chat(const gchar* const contact_barejid, const gchar* sta
|
||||
|
||||
// For "last N messages": back up from read_to using index
|
||||
if (!from_start) {
|
||||
int margin_entries = (MESSAGES_TO_RETRIEVE * 3) / FF_INDEX_STEP + 2;
|
||||
size_t margin_entries = (MESSAGES_TO_RETRIEVE * 3) / FF_INDEX_STEP + 2;
|
||||
|
||||
// Find index entry closest to (but before) read_to
|
||||
size_t entry_idx = 0;
|
||||
@@ -781,7 +781,7 @@ _flatfile_get_previous_chat(const gchar* const contact_barejid, const gchar* sta
|
||||
entry_idx = i;
|
||||
}
|
||||
|
||||
size_t start_entry = entry_idx > (size_t)margin_entries
|
||||
size_t start_entry = entry_idx > margin_entries
|
||||
? entry_idx - margin_entries
|
||||
: 0;
|
||||
off_t backed = state->entries[start_entry].byte_offset;
|
||||
|
||||
@@ -553,7 +553,7 @@ ff_split_meta(const char* meta)
|
||||
continue;
|
||||
}
|
||||
if (*p == '|' || *p == '\0') {
|
||||
g_ptr_array_add(arr, g_strndup(start, p - start));
|
||||
g_ptr_array_add(arr, g_strndup(start, g_diff_to_gsize(p, start)));
|
||||
if (*p == '\0')
|
||||
break;
|
||||
start = p + 1;
|
||||
@@ -710,7 +710,7 @@ ff_parse_line(const char* line)
|
||||
|
||||
if (bracket_start && first_space && first_space < bracket_start) {
|
||||
// Standard format with metadata: {timestamp} [{meta}] {sender}: {msg}
|
||||
result->timestamp_str = g_strndup(work, first_space - work);
|
||||
result->timestamp_str = g_strndup(work, g_diff_to_gsize(first_space, work));
|
||||
|
||||
// Parse metadata section [...]
|
||||
const char* bracket_end = ff_find_unescaped_char(bracket_start + 1, ']');
|
||||
@@ -721,7 +721,7 @@ ff_parse_line(const char* line)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
auto_gchar gchar* meta_content = g_strndup(bracket_start + 1, bracket_end - bracket_start - 1);
|
||||
auto_gchar gchar* meta_content = g_strndup(bracket_start + 1, g_diff_to_gsize(bracket_end, bracket_start + 1));
|
||||
char** parts = ff_split_meta(meta_content);
|
||||
if (parts) {
|
||||
_ff_parse_meta_parts(parts, result);
|
||||
@@ -736,12 +736,12 @@ ff_parse_line(const char* line)
|
||||
// Find first *unescaped* ': ' which separates sender from message.
|
||||
const char* colon = ff_find_unescaped_colonspace(after_meta);
|
||||
if (colon) {
|
||||
auto_gchar gchar* raw_sender = g_strndup(after_meta, colon - after_meta);
|
||||
auto_gchar gchar* raw_sender = g_strndup(after_meta, g_diff_to_gsize(colon, after_meta));
|
||||
|
||||
// Split sender into jid/resource, then unescape resource
|
||||
char* slash = strchr(raw_sender, '/');
|
||||
if (slash) {
|
||||
result->from_jid = g_strndup(raw_sender, slash - raw_sender);
|
||||
result->from_jid = g_strndup(raw_sender, g_diff_to_gsize(slash, raw_sender));
|
||||
result->from_resource = ff_unescape_sender_resource(slash + 1);
|
||||
} else {
|
||||
result->from_jid = g_strdup(raw_sender);
|
||||
@@ -755,7 +755,7 @@ ff_parse_line(const char* line)
|
||||
}
|
||||
} else if (first_space) {
|
||||
// Legacy/simple format without metadata: {timestamp} - {sender}: {msg}
|
||||
result->timestamp_str = g_strndup(work, first_space - work);
|
||||
result->timestamp_str = g_strndup(work, g_diff_to_gsize(first_space, work));
|
||||
result->type = g_strdup("chat");
|
||||
result->enc = g_strdup("none");
|
||||
|
||||
@@ -767,10 +767,10 @@ ff_parse_line(const char* line)
|
||||
|
||||
char* colon = strstr(rest, ": ");
|
||||
if (colon) {
|
||||
char* sender = g_strndup(rest, colon - rest);
|
||||
char* sender = g_strndup(rest, g_diff_to_gsize(colon, rest));
|
||||
char* slash = strchr(sender, '/');
|
||||
if (slash) {
|
||||
result->from_jid = g_strndup(sender, slash - sender);
|
||||
result->from_jid = g_strndup(sender, g_diff_to_gsize(slash, sender));
|
||||
result->from_resource = g_strdup(slash + 1);
|
||||
} else {
|
||||
result->from_jid = g_strdup(sender);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#ifndef EVENT_COMMON_H
|
||||
#define EVENT_COMMON_H
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
void ev_disconnect_cleanup(void);
|
||||
void ev_inc_connection_counter(void);
|
||||
void ev_reset_connection_counter(void);
|
||||
|
||||
@@ -341,7 +341,7 @@ sv_ev_room_message(ProfMessage* message)
|
||||
status_bar_active(num, WIN_MUC, mucwin->roomjid);
|
||||
|
||||
if ((g_strcmp0(mynick, message->from_jid->resourcepart) != 0) && (prefs_get_boolean(PREF_BEEP))) {
|
||||
beep();
|
||||
ui_beep();
|
||||
}
|
||||
|
||||
// not currently on groupchat window
|
||||
@@ -349,7 +349,7 @@ sv_ev_room_message(ProfMessage* message)
|
||||
status_bar_new(num, WIN_MUC, mucwin->roomjid);
|
||||
|
||||
if ((g_strcmp0(mynick, message->from_jid->resourcepart) != 0) && (prefs_get_boolean(PREF_FLASH))) {
|
||||
flash();
|
||||
ui_flash();
|
||||
}
|
||||
|
||||
cons_show_incoming_room_message(message->from_jid->resourcepart, mucwin->roomjid, num, mention, triggers, mucwin->unread, window);
|
||||
|
||||
@@ -260,7 +260,12 @@ omemo_on_connect(ProfAccount* account)
|
||||
return;
|
||||
}
|
||||
|
||||
_omemo_finalize_identity_load(account);
|
||||
if (!_omemo_finalize_identity_load(account)) {
|
||||
omemo_ctx.loaded = FALSE;
|
||||
log_error("[OMEMO] failed to load OMEMO state from disk for %s", account->jid);
|
||||
cons_show_error("OMEMO: could not load encryption state from disk; OMEMO will be unavailable this session.");
|
||||
return;
|
||||
}
|
||||
|
||||
wins_omemo_trust_changed(NULL);
|
||||
}
|
||||
@@ -804,6 +809,10 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
|
||||
tag_len = AES128_GCM_TAG_LENGTH;
|
||||
tag = gcry_malloc_secure(tag_len);
|
||||
key_tag = gcry_malloc_secure(AES128_GCM_KEY_LENGTH + AES128_GCM_TAG_LENGTH);
|
||||
if (!tag || !key_tag) {
|
||||
log_error("[OMEMO][SEND] cannot allocate secure buffers");
|
||||
goto out;
|
||||
}
|
||||
|
||||
key = gcry_random_bytes_secure(AES128_GCM_KEY_LENGTH + AES128_GCM_IV_LENGTH, GCRY_VERY_STRONG_RANDOM);
|
||||
if (!key) {
|
||||
@@ -1274,8 +1283,12 @@ omemo_is_trusted_identity(const char* const jid, const char* const fingerprint)
|
||||
.device_id = GPOINTER_TO_UINT(device_id),
|
||||
};
|
||||
|
||||
size_t fingerprint_len;
|
||||
size_t fingerprint_len = 0;
|
||||
unsigned char* fingerprint_raw = _omemo_fingerprint_decode(fingerprint, &fingerprint_len);
|
||||
if (!fingerprint_raw) {
|
||||
log_error("[OMEMO] omemo_is_trusted_identity: failed to decode fingerprint for %s", jid);
|
||||
return FALSE;
|
||||
}
|
||||
unsigned char djb_type[] = { '\x05' };
|
||||
signal_buffer* buffer = signal_buffer_create(djb_type, 1);
|
||||
buffer = signal_buffer_append(buffer, fingerprint_raw, fingerprint_len);
|
||||
@@ -1459,6 +1472,10 @@ _omemo_fingerprint(ec_public_key* identity, gboolean formatted)
|
||||
static unsigned char*
|
||||
_omemo_fingerprint_decode(const char* const fingerprint, size_t* len)
|
||||
{
|
||||
if (!fingerprint) {
|
||||
*len = 0;
|
||||
return NULL;
|
||||
}
|
||||
unsigned char* output = malloc(strlen(fingerprint) / 2 + 1);
|
||||
if (!output) {
|
||||
*len = 0;
|
||||
@@ -1525,6 +1542,11 @@ omemo_trust(const char* const jid, const char* const fingerprint_formatted)
|
||||
};
|
||||
|
||||
unsigned char* fingerprint_raw = _omemo_fingerprint_decode(fingerprint_formatted, &len);
|
||||
if (!fingerprint_raw) {
|
||||
log_error("[OMEMO] omemo_trust: failed to decode fingerprint for %s", jid);
|
||||
cons_show_error("Failed to trust device: could not decode fingerprint.");
|
||||
return;
|
||||
}
|
||||
unsigned char djb_type[] = { '\x05' };
|
||||
signal_buffer* buffer = signal_buffer_create(djb_type, 1);
|
||||
buffer = signal_buffer_append(buffer, fingerprint_raw, len);
|
||||
@@ -1542,8 +1564,10 @@ omemo_untrust(const char* const jid, const char* const fingerprint_formatted)
|
||||
{
|
||||
size_t len;
|
||||
unsigned char* identity = _omemo_fingerprint_decode(fingerprint_formatted, &len);
|
||||
if (!identity)
|
||||
if (!identity) {
|
||||
log_error("[OMEMO] omemo_untrust: failed to decode fingerprint for %s", jid);
|
||||
return;
|
||||
}
|
||||
|
||||
GHashTableIter iter;
|
||||
gpointer key, value;
|
||||
@@ -1993,10 +2017,6 @@ _cache_device_identity(const char* const jid, uint32_t device_id, ec_public_key*
|
||||
g_hash_table_insert(omemo_static_data.fingerprint_ac, strdup(jid), ac);
|
||||
}
|
||||
|
||||
if (!fingerprint) {
|
||||
return;
|
||||
}
|
||||
|
||||
char* formatted_fingerprint = omemo_format_fingerprint(fingerprint);
|
||||
if (formatted_fingerprint) {
|
||||
autocomplete_add(ac, formatted_fingerprint);
|
||||
|
||||
@@ -278,7 +278,8 @@ otr_on_message_recv(const char* const barejid, const char* const resource, const
|
||||
if (strstr(message, OTRL_MESSAGE_TAG_V2) && strstr(message, OTRL_MESSAGE_TAG_V1)) {
|
||||
tag_length = 32;
|
||||
}
|
||||
memmove(whitespace_base, whitespace_base + tag_length, tag_length);
|
||||
// Move the rest of the message (with NUL) over the tag.
|
||||
memmove(whitespace_base, whitespace_base + tag_length, strlen(whitespace_base + tag_length) + 1);
|
||||
char* otr_query_message = otr_start_query();
|
||||
cons_show("OTR Whitespace pattern detected. Attempting to start OTR session…");
|
||||
free(message_send_chat_otr(barejid, otr_query_message, FALSE, NULL));
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#ifndef PGP_GPG_H
|
||||
#define PGP_GPG_H
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
typedef struct pgp_key_t
|
||||
{
|
||||
gchar* id;
|
||||
|
||||
@@ -70,6 +70,38 @@ static void _connect_default(const char* const account);
|
||||
pthread_mutex_t lock;
|
||||
static gboolean force_quit = FALSE;
|
||||
|
||||
static volatile sig_atomic_t suspend_requested = FALSE;
|
||||
static volatile sig_atomic_t cont_requested = FALSE;
|
||||
|
||||
static void
|
||||
_handle_suspend_signals(void)
|
||||
{
|
||||
if (cont_requested) {
|
||||
cont_requested = FALSE;
|
||||
if (!editor_is_active()) {
|
||||
clearok(stdscr, TRUE);
|
||||
ui_resize();
|
||||
}
|
||||
}
|
||||
|
||||
if (editor_check_stopped()) {
|
||||
log_info("[Editor] stopped; aborting back to profanity");
|
||||
suspend_requested = FALSE;
|
||||
editor_emergency_kill();
|
||||
} else if (suspend_requested) {
|
||||
suspend_requested = FALSE;
|
||||
if (editor_is_active()) {
|
||||
log_info("[Editor] SIGTSTP from vim group; deferring to next poll");
|
||||
} else {
|
||||
log_info("[Suspend] dropping to shell");
|
||||
if (!isendwin()) {
|
||||
endwin();
|
||||
}
|
||||
kill(0, SIGSTOP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_run(gchar* log_level, gchar* account_name, gchar* config_file, gchar* log_file, gchar* theme_name, gchar** commands)
|
||||
{
|
||||
@@ -93,6 +125,7 @@ prof_run(gchar* log_level, gchar* account_name, gchar* config_file, gchar* log_f
|
||||
int waittime = 0;
|
||||
while (cont && !force_quit) {
|
||||
log_stderr_handler();
|
||||
_handle_suspend_signals();
|
||||
session_check_autoaway();
|
||||
|
||||
line = commands ? *commands : inp_readline();
|
||||
@@ -105,7 +138,7 @@ prof_run(gchar* log_level, gchar* account_name, gchar* config_file, gchar* log_f
|
||||
* so we can be sure there's runtime left after executing
|
||||
* the last command.
|
||||
*/
|
||||
min_runtime += waittime;
|
||||
min_runtime += (unsigned int)waittime;
|
||||
} else {
|
||||
log_error("%s", err_msg);
|
||||
g_free(err_msg);
|
||||
@@ -182,6 +215,18 @@ sigterm_handler(int sig)
|
||||
force_quit = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
sigtstp_handler(int sig)
|
||||
{
|
||||
suspend_requested = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
sigcont_handler(int sig)
|
||||
{
|
||||
cont_requested = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_init(char* log_level, char* config_file, char* log_file, char* theme_name)
|
||||
{
|
||||
@@ -189,7 +234,8 @@ _init(char* log_level, char* config_file, char* log_file, char* theme_name)
|
||||
// ignore SIGPIPE
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
signal(SIGINT, SIG_IGN);
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGTSTP, sigtstp_handler);
|
||||
signal(SIGCONT, sigcont_handler);
|
||||
signal(SIGWINCH, ui_sigwinch_handler);
|
||||
signal(SIGTERM, sigterm_handler);
|
||||
signal(SIGHUP, sigterm_handler);
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
#ifndef BOOKMARK_IGNORE_H
|
||||
#define BOOKMARK_IGNORE_H
|
||||
|
||||
#include "xmpp/xmpp.h"
|
||||
|
||||
void bookmark_ignore_on_connect(const char* const barejid);
|
||||
void bookmark_ignore_on_disconnect(void);
|
||||
void bookmark_ignore_on_disconnect();
|
||||
gboolean bookmark_ignored(Bookmark* bookmark);
|
||||
gchar** bookmark_ignore_list(gsize* len);
|
||||
void bookmark_ignore_add(const char* const barejid);
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "ncurses.h"
|
||||
#include "ui/ui.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
typedef struct EditorContext
|
||||
{
|
||||
@@ -33,9 +32,15 @@ typedef struct EditorContext
|
||||
void* user_data;
|
||||
} EditorContext;
|
||||
|
||||
static gboolean editor_active = FALSE; // re-entrancy guard
|
||||
static pid_t editor_pid = 0;
|
||||
|
||||
static void
|
||||
_editor_exit_cb(GPid pid, gint status, gpointer data)
|
||||
{
|
||||
editor_active = FALSE;
|
||||
editor_pid = 0;
|
||||
|
||||
EditorContext* ctx = data;
|
||||
gchar* contents = NULL;
|
||||
GError* error = NULL;
|
||||
@@ -53,8 +58,10 @@ _editor_exit_cb(GPid pid, gint status, gpointer data)
|
||||
cons_show_error("Could not read edited content: %s", error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
} else {
|
||||
cons_show_error("Editor exited with error status %d", WEXITSTATUS(status));
|
||||
} else if (WIFEXITED(status)) {
|
||||
cons_show_error("Editor exited with status %d", WEXITSTATUS(status));
|
||||
} else if (WIFSIGNALED(status)) {
|
||||
cons_show("Editor session cancelled.");
|
||||
}
|
||||
|
||||
if (remove(ctx->filename) != 0) {
|
||||
@@ -71,6 +78,11 @@ _editor_exit_cb(GPid pid, gint status, gpointer data)
|
||||
gboolean
|
||||
launch_editor(gchar* initial_content, void (*callback)(gchar* content, void* data), void* user_data)
|
||||
{
|
||||
if (editor_active) {
|
||||
cons_show_error("An editor session is already active.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto_gchar gchar* filename = NULL;
|
||||
auto_gerror GError* glib_error = NULL;
|
||||
const char* jid = connection_get_barejid();
|
||||
@@ -119,17 +131,19 @@ launch_editor(gchar* initial_content, void (*callback)(gchar* content, void* dat
|
||||
ctx->callback = callback;
|
||||
ctx->user_data = user_data;
|
||||
|
||||
editor_active = TRUE;
|
||||
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);
|
||||
// Force GLib to install its SIGCHLD handler before forking. Creating a
|
||||
// GChildWatchSource for our own pid is the documented trigger; we never
|
||||
// attach or dispatch it, just rely on the side effect.
|
||||
GSource* sigchld_warmup = g_child_watch_source_new(getpid());
|
||||
g_source_unref(sigchld_warmup);
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid == -1) {
|
||||
log_error("[Editor] Failed to fork: %s", strerror(errno));
|
||||
editor_active = FALSE;
|
||||
ui_resume();
|
||||
ui_resize();
|
||||
cons_show_error("Failed to start editor: %s", strerror(errno));
|
||||
@@ -140,7 +154,8 @@ launch_editor(gchar* initial_content, void (*callback)(gchar* content, void* dat
|
||||
} else if (pid == 0) {
|
||||
// Child process: Inherits TTY from parent
|
||||
|
||||
// Reset signal handlers that profanity sets so the editor doesn't inherit them
|
||||
// SIGTSTP=SIG_DFL lets vim's :stop / Ctrl-Z work; profanity catches
|
||||
// the STOPPED state via editor_check_stopped() and drops to the shell.
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGTSTP, SIG_DFL);
|
||||
signal(SIGPIPE, SIG_DFL);
|
||||
@@ -152,7 +167,39 @@ launch_editor(gchar* initial_content, void (*callback)(gchar* content, void* dat
|
||||
}
|
||||
|
||||
// Parent process: Watch the child asynchronously
|
||||
editor_pid = pid;
|
||||
g_child_watch_add((GPid)pid, _editor_exit_cb, ctx);
|
||||
g_strfreev(editor_argv);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
editor_emergency_kill(void)
|
||||
{
|
||||
if (!editor_active || editor_pid <= 0) {
|
||||
return;
|
||||
}
|
||||
log_warning("[Editor] aborting editor pid %d", editor_pid);
|
||||
kill(editor_pid, SIGCONT); // wake if STOPPED; no-op otherwise
|
||||
kill(editor_pid, SIGTERM);
|
||||
// _editor_exit_cb will restore the UI when the child reaps.
|
||||
}
|
||||
|
||||
gboolean
|
||||
editor_is_active(void)
|
||||
{
|
||||
return editor_active;
|
||||
}
|
||||
|
||||
gboolean
|
||||
editor_check_stopped(void)
|
||||
{
|
||||
// Poll for STOPPED without reaping (g_child_watch handles exit via its
|
||||
// own WNOHANG). Lets prof_run drop the group to the shell on Ctrl-Z.
|
||||
if (!editor_active || editor_pid <= 0) {
|
||||
return FALSE;
|
||||
}
|
||||
int status;
|
||||
pid_t r = waitpid(editor_pid, &status, WNOHANG | WUNTRACED);
|
||||
return (r == editor_pid && WIFSTOPPED(status));
|
||||
}
|
||||
|
||||
@@ -16,4 +16,13 @@
|
||||
|
||||
gboolean launch_editor(gchar* initial_content, void (*callback)(gchar* content, void* data), void* user_data);
|
||||
|
||||
void editor_emergency_kill(void); // SIGCONT+SIGTERM the editor child
|
||||
|
||||
// TRUE if editor child is STOPPED (Ctrl-Z / :stop / gdb-attach). Does not
|
||||
// reap; g_child_watch keeps handling exit.
|
||||
gboolean editor_check_stopped(void);
|
||||
|
||||
// Editor-session flag accessor. Used by prof_run on SIGCONT resume.
|
||||
gboolean editor_is_active(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -327,7 +327,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
|
||||
cons_show_incoming_message(display_name, num, chatwin->unread, window);
|
||||
|
||||
if (prefs_get_boolean(PREF_FLASH)) {
|
||||
flash();
|
||||
ui_flash();
|
||||
}
|
||||
|
||||
chatwin->unread++;
|
||||
@@ -364,7 +364,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
|
||||
wins_add_quotes_ac(window, message->plain, FALSE);
|
||||
|
||||
if (prefs_get_boolean(PREF_BEEP)) {
|
||||
beep();
|
||||
ui_beep();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,8 +399,6 @@ chatwin_outgoing_msg(ProfChatWin* chatwin, const char* const message, const char
|
||||
win_print_outgoing((ProfWin*)chatwin, enc_char, id, replace_id, display_message);
|
||||
}
|
||||
|
||||
plugins_post_chat_message_display(myjid->barejid, myjid->resourcepart, display_message);
|
||||
|
||||
// Save last id and message for LMC
|
||||
// Note: if the same message is to be corrected several times, the id of the original message is used in each case
|
||||
// https://xmpp.org/extensions/xep-0308.html#rules
|
||||
@@ -434,7 +432,6 @@ chatwin_outgoing_carbon(ProfChatWin* chatwin, ProfMessage* message)
|
||||
|
||||
win_print_outgoing(window, enc_char, message->id, message->replace_id, message->plain);
|
||||
|
||||
plugins_post_chat_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
|
||||
message->plain = old_plain;
|
||||
|
||||
int num = wins_get_num(window);
|
||||
@@ -561,7 +558,6 @@ _chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid)
|
||||
if (plugin_msg)
|
||||
msg->plain = plugin_msg;
|
||||
win_print_history((ProfWin*)chatwin, msg);
|
||||
plugins_post_chat_message_display(msg->from_jid->barejid, msg->from_jid->resourcepart, msg->plain);
|
||||
msg->plain = old_plain;
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
@@ -601,7 +597,6 @@ chatwin_db_history(ProfChatWin* chatwin, const gchar* start_time, const gchar* e
|
||||
} else {
|
||||
win_print_history((ProfWin*)chatwin, msg);
|
||||
}
|
||||
plugins_post_chat_message_display(msg->from_jid->barejid, msg->from_jid->resourcepart, msg->plain);
|
||||
msg->plain = old_plain;
|
||||
curr = g_slist_next(curr);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
|
||||
static int inp_size;
|
||||
static gboolean perform_resize = FALSE;
|
||||
static gboolean ui_suspended = FALSE;
|
||||
static GTimer* ui_idle_time;
|
||||
static WINDOW* main_scr;
|
||||
|
||||
@@ -63,6 +64,14 @@ static Display* display;
|
||||
|
||||
static void _ui_draw_term_title(void);
|
||||
|
||||
// Fail-safe gate: authoritative flag (doesn't depend on isendwin staying
|
||||
// TRUE), plus the regular endwin check for shutdown.
|
||||
static gboolean
|
||||
_ui_redraw_suspended(void)
|
||||
{
|
||||
return ui_suspended || isendwin();
|
||||
}
|
||||
|
||||
static void
|
||||
_ui_close(void)
|
||||
{
|
||||
@@ -120,8 +129,7 @@ ui_sigwinch_handler(int sig)
|
||||
void
|
||||
ui_update(void)
|
||||
{
|
||||
// UI is suspended
|
||||
if (isendwin()) {
|
||||
if (_ui_redraw_suspended()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,7 +146,7 @@ ui_update(void)
|
||||
title_bar_update_virtual();
|
||||
status_bar_draw();
|
||||
inp_put_back();
|
||||
doupdate();
|
||||
prof_doupdate();
|
||||
|
||||
if (perform_resize) {
|
||||
perform_resize = FALSE;
|
||||
@@ -180,21 +188,49 @@ void
|
||||
ui_suspend(void)
|
||||
{
|
||||
inp_suspend();
|
||||
// Flush before flipping the flag (prof_doupdate skips while suspended).
|
||||
prof_doupdate();
|
||||
ui_suspended = TRUE;
|
||||
endwin();
|
||||
}
|
||||
|
||||
void
|
||||
ui_resume(void)
|
||||
{
|
||||
ui_suspended = FALSE;
|
||||
clearok(stdscr, TRUE); // ncurses can't see vim's screen clobber
|
||||
refresh();
|
||||
inp_resume();
|
||||
}
|
||||
|
||||
void
|
||||
ui_beep(void)
|
||||
{
|
||||
if (!isendwin()) {
|
||||
beep();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ui_flash(void)
|
||||
{
|
||||
if (!isendwin()) {
|
||||
flash();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_doupdate(void)
|
||||
{
|
||||
if (!_ui_redraw_suspended()) {
|
||||
doupdate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ui_resize(void)
|
||||
{
|
||||
// UI is suspended
|
||||
if (isendwin()) {
|
||||
if (_ui_redraw_suspended()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -216,8 +252,7 @@ ui_resize(void)
|
||||
void
|
||||
ui_redraw(void)
|
||||
{
|
||||
// UI is suspended
|
||||
if (isendwin()) {
|
||||
if (_ui_redraw_suspended()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,11 @@ inp_readline(void)
|
||||
{
|
||||
// UI is suspended
|
||||
if (is_suspended || isendwin()) {
|
||||
// Mirror the normal-path unlock so workers aren't starved
|
||||
// for the whole editor session.
|
||||
pthread_mutex_unlock(&lock);
|
||||
g_usleep(100000); // 100ms
|
||||
pthread_mutex_lock(&lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -311,11 +315,13 @@ inp_get_line(void)
|
||||
werase(inp_win);
|
||||
wmove(inp_win, 0, 0);
|
||||
_inp_win_update_virtual();
|
||||
doupdate();
|
||||
prof_doupdate();
|
||||
char* line = NULL;
|
||||
while (!line) {
|
||||
line = inp_readline();
|
||||
ui_update();
|
||||
while (g_main_context_iteration(NULL, FALSE)) // non-blocking; bounded by ready sources
|
||||
;
|
||||
}
|
||||
status_bar_clear_prompt();
|
||||
return line;
|
||||
@@ -338,12 +344,14 @@ inp_get_password(void)
|
||||
werase(inp_win);
|
||||
wmove(inp_win, 0, 0);
|
||||
_inp_win_update_virtual();
|
||||
doupdate();
|
||||
prof_doupdate();
|
||||
char* password = NULL;
|
||||
get_password = TRUE;
|
||||
while (!password) {
|
||||
password = inp_readline();
|
||||
ui_update();
|
||||
while (g_main_context_iteration(NULL, FALSE)) // non-blocking; bounded by ready sources
|
||||
;
|
||||
}
|
||||
get_password = FALSE;
|
||||
status_bar_clear_prompt();
|
||||
@@ -459,7 +467,7 @@ _inp_write(char* line, int offset)
|
||||
_inp_win_handle_scroll();
|
||||
|
||||
_inp_win_update_virtual();
|
||||
doupdate();
|
||||
prof_doupdate();
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -57,7 +57,7 @@ privwin_incoming_msg(ProfPrivateWin* privatewin, ProfMessage* message)
|
||||
privatewin->unread++;
|
||||
|
||||
if (prefs_get_boolean(PREF_FLASH)) {
|
||||
flash();
|
||||
ui_flash();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ privwin_incoming_msg(ProfPrivateWin* privatewin, ProfMessage* message)
|
||||
wins_add_quotes_ac(window, message->plain, TRUE);
|
||||
|
||||
if (prefs_get_boolean(PREF_BEEP)) {
|
||||
beep();
|
||||
ui_beep();
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
|
||||
@@ -170,12 +170,7 @@ status_bar_current(guint i)
|
||||
void
|
||||
status_bar_inactive(const int win)
|
||||
{
|
||||
int true_win = win;
|
||||
if (true_win == 0) {
|
||||
true_win = 10;
|
||||
}
|
||||
|
||||
g_hash_table_remove(statusbar->tabs, GINT_TO_POINTER(true_win));
|
||||
g_hash_table_remove(statusbar->tabs, GINT_TO_POINTER((win == 0) ? CONSOLE_TAB_ID : win));
|
||||
|
||||
status_bar_draw();
|
||||
}
|
||||
@@ -183,8 +178,6 @@ status_bar_inactive(const int win)
|
||||
void
|
||||
_create_tab(const int win, win_type_t wintype, char* identifier, gboolean highlight)
|
||||
{
|
||||
int true_win = win == 0 ? 10 : win;
|
||||
|
||||
StatusBarTab* tab = g_new0(StatusBarTab, 1);
|
||||
tab->identifier = strdup(identifier);
|
||||
tab->highlight = highlight;
|
||||
@@ -214,7 +207,7 @@ _create_tab(const int win, win_type_t wintype, char* identifier, gboolean highli
|
||||
}
|
||||
}
|
||||
|
||||
g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab);
|
||||
g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER((win == 0) ? CONSOLE_TAB_ID : win), tab);
|
||||
|
||||
status_bar_draw();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#ifndef UI_TITLEBAR_H
|
||||
#define UI_TITLEBAR_H
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
void create_title_bar(void);
|
||||
void free_title_bar(void);
|
||||
void title_bar_update_virtual(void);
|
||||
|
||||
@@ -43,6 +43,9 @@ void ui_load_colours(void);
|
||||
void ui_update(void);
|
||||
void ui_redraw(void);
|
||||
void ui_resize(void);
|
||||
// doupdate() wrapper that skips when the UI is suspended. Use this instead
|
||||
// of raw doupdate() to avoid the per-site whitelist class of bug.
|
||||
void prof_doupdate(void);
|
||||
void ui_focus_win(ProfWin* window);
|
||||
void ui_sigwinch_handler(int sig);
|
||||
void ui_handle_otr_error(const char* const barejid, const char* const message);
|
||||
@@ -84,6 +87,8 @@ void ui_handle_recipient_error(const char* const recipient, const char* const er
|
||||
void ui_handle_error(const char* const err_msg);
|
||||
void ui_clear_win_title(void);
|
||||
void ui_goodbye_title(void);
|
||||
void ui_beep(void);
|
||||
void ui_flash(void);
|
||||
void ui_handle_room_configuration_form_error(const char* const roomjid, const char* const message);
|
||||
void ui_handle_room_config_submit_result(const char* const roomjid);
|
||||
void ui_handle_room_config_submit_result_error(const char* const roomjid, const char* const message);
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include "ai/ai_client.h"
|
||||
|
||||
static const int PAD_MIN_HEIGHT = 100;
|
||||
static const int PAD_THRESHOLD = 3000;
|
||||
static const int PAD_THRESHOLD = 12000; // above buffer cap (~9000): reclaims dead pad space, never fires while scrolling
|
||||
static gboolean _in_redraw = FALSE;
|
||||
|
||||
static void
|
||||
@@ -2172,9 +2172,10 @@ win_redraw(ProfWin* window)
|
||||
unsigned int size = buffer_size(window->layout->buffer);
|
||||
_in_redraw = TRUE;
|
||||
|
||||
// shrink pad back to minimum size and erase it
|
||||
// size the pad to fit the whole buffer (plus headroom) and erase it
|
||||
int cols = getmaxx(window->layout->win);
|
||||
wresize(window->layout->win, PAD_MIN_HEIGHT, cols);
|
||||
int needed = window->layout->buffer->lines + 100;
|
||||
wresize(window->layout->win, MAX(needed, PAD_MIN_HEIGHT), cols);
|
||||
werase(window->layout->win);
|
||||
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#ifndef XMPP_BLOCKING_H
|
||||
#define XMPP_BLOCKING_H
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
void blocking_request(void);
|
||||
int blocked_set_handler(xmpp_stanza_t* stanza);
|
||||
int reporting_set_handler(xmpp_stanza_t* stanza);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#ifndef XMPP_IQ_H
|
||||
#define XMPP_IQ_H
|
||||
|
||||
#include <strophe.h>
|
||||
|
||||
typedef int (*ProfIqCallback)(xmpp_stanza_t* const stanza, void* const userdata);
|
||||
typedef void (*ProfIqFreeCallback)(void* userdata);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
#include "xmpp/jid.h"
|
||||
|
||||
#define JID_MAX_PART_LEN 1023
|
||||
@@ -116,7 +117,7 @@ jid_is_valid(const gchar* const str)
|
||||
|
||||
// Localpart validation
|
||||
if (at) {
|
||||
size_t local_len = at - str;
|
||||
size_t local_len = g_diff_to_gsize(at, str);
|
||||
if (local_len == 0 || local_len > JID_MAX_PART_LEN) {
|
||||
return FALSE;
|
||||
}
|
||||
@@ -134,7 +135,7 @@ jid_is_valid(const gchar* const str)
|
||||
|
||||
// Resourcepart validation if present
|
||||
if (slash) {
|
||||
domain_len = slash - domain_start;
|
||||
domain_len = g_diff_to_gsize(slash, domain_start);
|
||||
size_t resource_len = strlen(slash + 1);
|
||||
if (resource_len > JID_MAX_PART_LEN) {
|
||||
return FALSE;
|
||||
|
||||
@@ -65,6 +65,7 @@ static void _handle_pubsub(xmpp_stanza_t* const stanza, xmpp_stanza_t* const eve
|
||||
static gboolean _handle_form(xmpp_stanza_t* const stanza);
|
||||
static gboolean _handle_jingle_message(xmpp_stanza_t* const stanza);
|
||||
static gboolean _should_ignore_based_on_silence(xmpp_stanza_t* const stanza);
|
||||
static gboolean _stanza_id_by_trusted(const char* by);
|
||||
#ifdef HAVE_OMEMO
|
||||
static void _receive_omemo(xmpp_stanza_t* const stanza, ProfMessage* message);
|
||||
#endif
|
||||
@@ -1088,7 +1089,7 @@ _handle_groupchat(xmpp_stanza_t* const stanza)
|
||||
xmpp_stanza_t* stanzaidst = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_STANZA_ID, STANZA_NS_STABLE_ID);
|
||||
if (stanzaidst) {
|
||||
const char* by = xmpp_stanza_get_attribute(stanzaidst, "by");
|
||||
if (by && (g_strcmp0(by, from_jid->barejid) == 0)) {
|
||||
if (by && g_strcmp0(by, from_jid->barejid) == 0 && _stanza_id_by_trusted(by)) {
|
||||
stanzaid = (char*)xmpp_stanza_get_attribute(stanzaidst, STANZA_ATTR_ID);
|
||||
if (stanzaid) {
|
||||
message->stanzaid = strdup(stanzaid);
|
||||
@@ -1397,7 +1398,7 @@ _handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, c
|
||||
xmpp_stanza_t* stanzaidst = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_STANZA_ID, STANZA_NS_STABLE_ID);
|
||||
if (stanzaidst) {
|
||||
const char* by = xmpp_stanza_get_attribute(stanzaidst, "by");
|
||||
if (by && equals_our_barejid(by)) {
|
||||
if (by && equals_our_barejid(by) && _stanza_id_by_trusted(by)) {
|
||||
stanzaid = (char*)xmpp_stanza_get_attribute(stanzaidst, STANZA_ATTR_ID);
|
||||
if (stanzaid) {
|
||||
message->stanzaid = strdup(stanzaid);
|
||||
@@ -1735,3 +1736,22 @@ _should_ignore_based_on_silence(xmpp_stanza_t* const stanza)
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// XEP-0359 §6 disco-gate; falls back to domain since that's what disco is run against.
|
||||
static gboolean
|
||||
_stanza_id_by_trusted(const char* by)
|
||||
{
|
||||
if (!by) {
|
||||
return FALSE;
|
||||
}
|
||||
GHashTable* features = connection_get_features(by);
|
||||
if (features && g_hash_table_contains(features, STANZA_NS_STABLE_ID)) {
|
||||
return TRUE;
|
||||
}
|
||||
const char* at = strchr(by, '@');
|
||||
if (!at) {
|
||||
return FALSE;
|
||||
}
|
||||
features = connection_get_features(at + 1);
|
||||
return features && g_hash_table_contains(features, STANZA_NS_STABLE_ID);
|
||||
}
|
||||
|
||||
@@ -707,7 +707,7 @@ muc_autocomplete(ProfWin* window, const char* const input, gboolean previous)
|
||||
} else {
|
||||
search_str = last_space + 1;
|
||||
if (!chat_room->autocomplete_prefix) {
|
||||
chat_room->autocomplete_prefix = g_strndup(input, search_str - input);
|
||||
chat_room->autocomplete_prefix = g_strndup(input, g_diff_to_gsize(search_str, input));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later WITH OpenSSL-exception
|
||||
*/
|
||||
|
||||
#include "glib.h"
|
||||
|
||||
/*!
|
||||
* \page OX OX Implementation
|
||||
*
|
||||
|
||||
@@ -621,15 +621,20 @@ _available_handler(xmpp_stanza_t* const stanza)
|
||||
}
|
||||
|
||||
if (g_strcmp0(xmpp_presence->jid->barejid, my_jid->barejid) == 0) {
|
||||
connection_add_available_resource(resource);
|
||||
// Copy what we read before connection_add_available_resource() takes ownership.
|
||||
Resource* resource_for_roster = resource_copy(resource);
|
||||
auto_gchar gchar* resource_name = g_strdup(resource->name);
|
||||
auto_gchar gchar* resource_status = resource->status ? g_strdup(resource->status) : NULL;
|
||||
int resource_priority = resource->priority;
|
||||
resource_presence_t resource_presence = resource->presence;
|
||||
connection_add_available_resource(resource);
|
||||
sv_ev_contact_online(xmpp_presence->jid->barejid, resource_for_roster, xmpp_presence->last_activity, pgpsig);
|
||||
const char* account_name = session_get_account_name();
|
||||
int max_sessions = accounts_get_max_sessions(account_name);
|
||||
if (max_sessions > 0) {
|
||||
auto_gchar gchar* cur_resource = accounts_get_resource(account_name);
|
||||
int res_count = connection_count_available_resources();
|
||||
if (res_count > max_sessions && g_strcmp0(cur_resource, resource->name)) {
|
||||
if (res_count > max_sessions && g_strcmp0(cur_resource, resource_name)) {
|
||||
ProfWin* console = wins_get_console();
|
||||
ProfWin* current_window = wins_get_current();
|
||||
auto_gchar gchar* message = g_strdup_printf("Max sessions alarm! (%d/%d devices in use)", res_count, max_sessions);
|
||||
@@ -639,14 +644,14 @@ _available_handler(xmpp_stanza_t* const stanza)
|
||||
}
|
||||
notify(message, 10000, "Security alert");
|
||||
|
||||
const char* resource_presence = string_from_resource_presence(resource->presence);
|
||||
win_print(console, THEME_DEFAULT, "|", "New device info: \n %s (%d), %s", resource->name, resource->priority, resource_presence);
|
||||
const char* resource_presence_str = string_from_resource_presence(resource_presence);
|
||||
win_print(console, THEME_DEFAULT, "|", "New device info: \n %s (%d), %s", resource_name, resource_priority, resource_presence_str);
|
||||
|
||||
if (resource->status) {
|
||||
win_append(console, THEME_DEFAULT, ", \"%s\"", resource->status);
|
||||
if (resource_status) {
|
||||
win_append(console, THEME_DEFAULT, ", \"%s\"", resource_status);
|
||||
}
|
||||
win_appendln(console, THEME_DEFAULT, "");
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(my_jid->barejid, resource->name);
|
||||
auto_jid Jid* jidp = jid_create_from_bare_and_resource(my_jid->barejid, resource_name);
|
||||
EntityCapabilities* caps = caps_lookup(jidp->fulljid);
|
||||
|
||||
if (caps) {
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
#ifndef XMPP_ROSTER_H
|
||||
#define XMPP_ROSTER_H
|
||||
|
||||
#include "glib.h"
|
||||
#include <strophe.h>
|
||||
|
||||
void roster_request(void);
|
||||
void roster_set_handler(xmpp_stanza_t* const stanza);
|
||||
void roster_result_handler(xmpp_stanza_t* const stanza);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "ui/win_types.h"
|
||||
#include "xmpp/vcard.h"
|
||||
#include <strophe.h>
|
||||
|
||||
vCard* vcard_new();
|
||||
void vcard_free(vCard* vcard);
|
||||
|
||||
@@ -253,6 +253,10 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(message_receive_console),
|
||||
PROF_FUNC_TEST(message_receive_chatwin),
|
||||
|
||||
/* XEP-0359 disco gate for stanza-id trust */
|
||||
PROF_FUNC_TEST(stanza_id_dedup_fires_when_server_announces_sid0),
|
||||
PROF_FUNC_TEST(stanza_id_not_trusted_when_server_does_not_announce_sid0),
|
||||
|
||||
#ifdef HAVE_SQLITE
|
||||
/* MUC (groupchat) database — export/import of type="muc" messages */
|
||||
PROF_FUNC_TEST(muc_export_sqlite_to_flatfile),
|
||||
|
||||
@@ -119,10 +119,9 @@ _create_dir(const char* name)
|
||||
gboolean
|
||||
_mkdir_recursive(const char* dir)
|
||||
{
|
||||
int i;
|
||||
gboolean result = TRUE;
|
||||
|
||||
for (i = 1; i <= strlen(dir); i++) {
|
||||
for (size_t i = 1; i <= strlen(dir); i++) {
|
||||
if (dir[i] == '/' || dir[i] == '\0') {
|
||||
gchar* next_dir = g_strndup(dir, i);
|
||||
result = _create_dir(next_dir);
|
||||
|
||||
@@ -56,3 +56,70 @@ message_receive_chatwin(void **state)
|
||||
|
||||
assert_true(prof_output_regex("someuser@chatserv.org/laptop: .+How are you?"));
|
||||
}
|
||||
|
||||
// XEP-0359 disco gate: server announces urn:xmpp:sid:0 -> stanza-id trusted -> replay flagged as duplicate.
|
||||
void
|
||||
stanza_id_dedup_fires_when_server_announces_sid0(void **state)
|
||||
{
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq type='result' to='stabber@localhost/profanity' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='TestServer'/>"
|
||||
"<feature var='urn:xmpp:sid:0'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
stbbr_send(
|
||||
"<message id='m-trust-1' to='stabber@localhost' from='someuser@chatserv.org/laptop' type='chat'>"
|
||||
"<body>first</body>"
|
||||
"<stanza-id xmlns='urn:xmpp:sid:0' by='stabber@localhost' id='archive-id-42'/>"
|
||||
"</message>"
|
||||
);
|
||||
assert_true(prof_output_exact("<< chat message: someuser@chatserv.org/laptop (win 2)"));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='m-trust-2' to='stabber@localhost' from='someuser@chatserv.org/laptop' type='chat'>"
|
||||
"<body>replay</body>"
|
||||
"<stanza-id xmlns='urn:xmpp:sid:0' by='stabber@localhost' id='archive-id-42'/>"
|
||||
"</message>"
|
||||
);
|
||||
assert_true(prof_output_exact("Got a message with duplicate (server-generated) stanza-id from someuser@chatserv.org/laptop."));
|
||||
}
|
||||
|
||||
// XEP-0359 disco gate: server does NOT announce urn:xmpp:sid:0 -> stanza-id untrusted -> no replay error.
|
||||
void
|
||||
stanza_id_not_trusted_when_server_does_not_announce_sid0(void **state)
|
||||
{
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq type='result' to='stabber@localhost/profanity' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='TestServer'/>"
|
||||
"<feature var='urn:xmpp:ping'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
stbbr_send(
|
||||
"<message id='m-untrust-1' to='stabber@localhost' from='someuser@chatserv.org/laptop' type='chat'>"
|
||||
"<body>first</body>"
|
||||
"<stanza-id xmlns='urn:xmpp:sid:0' by='stabber@localhost' id='archive-id-77'/>"
|
||||
"</message>"
|
||||
);
|
||||
assert_true(prof_output_exact("<< chat message: someuser@chatserv.org/laptop (win 2)"));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='m-untrust-2' to='stabber@localhost' from='someuser@chatserv.org/laptop' type='chat'>"
|
||||
"<body>replay</body>"
|
||||
"<stanza-id xmlns='urn:xmpp:sid:0' by='stabber@localhost' id='archive-id-77'/>"
|
||||
"</message>"
|
||||
);
|
||||
|
||||
prof_timeout(2);
|
||||
assert_false(prof_output_exact("Got a message with duplicate (server-generated) stanza-id"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
void message_send(void **state);
|
||||
void message_receive_console(void **state);
|
||||
void message_receive_chatwin(void **state);
|
||||
void stanza_id_dedup_fires_when_server_announces_sid0(void **state);
|
||||
void stanza_id_not_trusted_when_server_does_not_announce_sid0(void **state);
|
||||
|
||||
@@ -85,6 +85,10 @@ void
|
||||
ui_resize(void)
|
||||
{
|
||||
}
|
||||
void
|
||||
prof_doupdate(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ui_focus_win(ProfWin* win)
|
||||
@@ -1475,3 +1479,13 @@ ui_is_suspended(void)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
ui_beep(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ui_flash(void)
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user