From 92eed34fb3ae8148ab71ae7581c3f01e46606d28 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Fri, 10 Mar 2023 11:15:43 +0100 Subject: [PATCH 1/6] remove compat code We already depend on libstrophe >= 0.12, so this code can go. Signed-off-by: Steffen Jaeckel --- src/xmpp/connection.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 3165a18e..be0c8418 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -847,8 +847,6 @@ connection_set_priority(const int priority) conn.priority = priority; } -#if defined(LIBXMPP_VERSION_MAJOR) && defined(LIBXMPP_VERSION_MINOR) \ - && ((LIBXMPP_VERSION_MAJOR > 0) || (LIBXMPP_VERSION_MINOR >= 12)) static xmpp_stanza_t* _get_soh_error(xmpp_stanza_t* error_stanza) { @@ -857,19 +855,6 @@ _get_soh_error(xmpp_stanza_t* error_stanza) XMPP_STANZA_NAME_IN_NS("see-other-host", STANZA_NS_XMPP_STREAMS), NULL); } -#else -static xmpp_stanza_t* -_get_soh_error(xmpp_stanza_t* error_stanza) -{ - const char* name = xmpp_stanza_get_name(error_stanza); - const char* ns = xmpp_stanza_get_ns(error_stanza); - if (!name || !ns || strcmp(name, "error") || strcmp(ns, STANZA_NS_STREAMS)) { - log_debug("_get_soh_error: could not find error stanza"); - return NULL; - } - return xmpp_stanza_get_child_by_name_and_ns(error_stanza, "see-other-host", STANZA_NS_XMPP_STREAMS); -} -#endif #if GLIB_CHECK_VERSION(2, 66, 0) static gboolean From e99c4b7128f5c95cf8665ef969848defa0d3bbd7 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Fri, 10 Mar 2023 11:16:51 +0100 Subject: [PATCH 2/6] simplify some code Signed-off-by: Steffen Jaeckel --- src/xmpp/connection.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index be0c8418..3eca29c4 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -863,12 +863,8 @@ _split_url(const char* alturi, gchar** host, gint* port) /* Construct a valid URI with `schema://` as `g_uri_split_network()` * requires this to be there. */ - const char* xmpp = "xmpp://"; - char* xmpp_uri = _xmalloc(strlen(xmpp) + strlen(alturi) + 1, NULL); - memcpy(xmpp_uri, xmpp, strlen(xmpp)); - memcpy(xmpp_uri + strlen(xmpp), alturi, strlen(alturi) + 1); + auto_gchar gchar* xmpp_uri = g_strdup_printf("xmpp://%s", alturi); gboolean ret = g_uri_split_network(xmpp_uri, 0, NULL, host, port, NULL); - free(xmpp_uri); /* fix-up `port` as g_uri_split_network() sets port to `-1` if it's missing * in the passed-in URI, but libstrophe expects a "missing port" * to be passed as `0` (which then results in connecting to the standard port). From 2925e85cd6e6c63ce5ba716e5de9d24066e9aebc Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Fri, 10 Mar 2023 14:51:43 +0100 Subject: [PATCH 3/6] add test-case for #1761 Signed-off-by: Steffen Jaeckel --- tests/unittests/test_common.c | 22 ++++++++++++++++++++++ tests/unittests/test_common.h | 1 + tests/unittests/unittests.c | 1 + 3 files changed, 24 insertions(+) diff --git a/tests/unittests/test_common.c b/tests/unittests/test_common.c index fa5dd59e..3812cccb 100644 --- a/tests/unittests/test_common.c +++ b/tests/unittests/test_common.c @@ -535,6 +535,28 @@ _lists_equal(GSList* a, GSList* b) return TRUE; } +void +prof_occurrences_of_large_message_tests(void** state) +{ + GSList* actual = NULL; + GSList* expected = NULL; + /* use this with the old implementation to create a segfault + * const size_t haystack_sz = 1024 * 1024; + */ + const size_t haystack_sz = 1024; + size_t haystack_cur = 0; + char* haystack = malloc(haystack_sz); + const char needle[] = "needle "; + while (haystack_sz - haystack_cur > sizeof(needle)) { + memcpy(&haystack[haystack_cur], needle, sizeof(needle) - 1); + expected = g_slist_append(expected, GINT_TO_POINTER(haystack_cur)); + haystack_cur += sizeof(needle) - 1; + } + assert_true(_lists_equal(prof_occurrences("needle", haystack, 0, FALSE, &actual), expected)); + g_slist_free(actual); + g_slist_free(expected); +} + void prof_partial_occurrences_tests(void** state) { diff --git a/tests/unittests/test_common.h b/tests/unittests/test_common.h index 46d990d9..ffcc6c9d 100644 --- a/tests/unittests/test_common.h +++ b/tests/unittests/test_common.h @@ -31,5 +31,6 @@ void strip_quotes_strips_last(void** state); void strip_quotes_strips_both(void** state); void prof_partial_occurrences_tests(void** state); void prof_whole_occurrences_tests(void** state); +void prof_occurrences_of_large_message_tests(void** state); void unique_filename_from_url_td(void** state); void format_call_external_argv_td(void** state); diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c index e2293004..2724aaa2 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -620,6 +620,7 @@ main(int argc, char* argv[]) unit_test(prof_partial_occurrences_tests), unit_test(prof_whole_occurrences_tests), + unit_test(prof_occurrences_of_large_message_tests), unit_test(returns_no_commands), unit_test(returns_commands), From 7167760bdd06db79ef81b82859639498f324d033 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Fri, 10 Mar 2023 14:52:54 +0100 Subject: [PATCH 4/6] fix #1761 by changing the implementation from recursive ... to an iterative approach Signed-off-by: Steffen Jaeckel --- src/common.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/common.c b/src/common.c index 7888a1dc..eabb45f3 100644 --- a/src/common.c +++ b/src/common.c @@ -355,33 +355,32 @@ prof_occurrences(const char* const needle, const char* const haystack, int offse return *result; } - gchar* haystack_curr = g_utf8_offset_to_pointer(haystack, offset); - if (g_str_has_prefix(haystack_curr, needle)) { - if (whole_word) { - gunichar before = 0; - gchar* haystack_before_ch = g_utf8_find_prev_char(haystack, haystack_curr); - if (haystack_before_ch) { - before = g_utf8_get_char(haystack_before_ch); - } + do { + gchar* haystack_curr = g_utf8_offset_to_pointer(haystack, offset); + if (g_str_has_prefix(haystack_curr, needle)) { + if (whole_word) { + gunichar before = 0; + gchar* haystack_before_ch = g_utf8_find_prev_char(haystack, haystack_curr); + if (haystack_before_ch) { + before = g_utf8_get_char(haystack_before_ch); + } - gunichar after = 0; - gchar* haystack_after_ch = haystack_curr + strlen(needle); - if (haystack_after_ch[0] != '\0') { - after = g_utf8_get_char(haystack_after_ch); - } + gunichar after = 0; + gchar* haystack_after_ch = haystack_curr + strlen(needle); + if (haystack_after_ch[0] != '\0') { + after = g_utf8_get_char(haystack_after_ch); + } - if (!g_unichar_isalnum(before) && !g_unichar_isalnum(after)) { + if (!g_unichar_isalnum(before) && !g_unichar_isalnum(after)) { + *result = g_slist_append(*result, GINT_TO_POINTER(offset)); + } + } else { *result = g_slist_append(*result, GINT_TO_POINTER(offset)); } - } else { - *result = g_slist_append(*result, GINT_TO_POINTER(offset)); } - } - offset++; - if (g_strcmp0(g_utf8_offset_to_pointer(haystack, offset), "\0") != 0) { - *result = prof_occurrences(needle, haystack, offset, whole_word, result); - } + offset++; + } while (g_strcmp0(g_utf8_offset_to_pointer(haystack, offset), "\0") != 0); return *result; } From 091987db946895cb415d6da726cc1fa7c445c6d2 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sun, 12 Mar 2023 17:37:21 +0100 Subject: [PATCH 5/6] fix #1797 Signed-off-by: Steffen Jaeckel --- src/omemo/omemo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index f654f33b..9104a8cb 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -1920,7 +1920,7 @@ char* omemo_qrcode_str() { char* mybarejid = connection_get_barejid(); - char* fingerprint = omemo_own_fingerprint(TRUE); + char* fingerprint = omemo_own_fingerprint(FALSE); uint32_t sid = omemo_device_id(); char* qrstr = g_strdup_printf("xmpp:%s?omemo-sid-%d=%s", mybarejid, sid, fingerprint); From 2936b09a63728c9ac0c1e92786d37fec673da8d2 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sun, 12 Mar 2023 17:38:49 +0100 Subject: [PATCH 6/6] change OMEMO QR code `0` bits to 'space' This makes the generated QR code a lot better recognizable in my case. Signed-off-by: Steffen Jaeckel --- src/ui/console.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index b1720415..bab8e17c 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -915,10 +915,12 @@ cons_show_qrcode(const char* const text) strcat(pad, "\u2588\u2588"); } - win_println(console, THEME_DEFAULT, "", pad); + win_println(console, THEME_DEFAULT, "", ""); + win_println(console, THEME_DEFAULT, "", ""); + win_println(console, THEME_DEFAULT, "", "%s", pad); for (size_t y = 0; y < width; y += ZOOM_SIZE) { for (size_t x = 0; x < width; x += ZOOM_SIZE) { - strcat(buf, !(*data & 1) ? "\u2588\u2588" : "\u2800\u2800"); + strcat(buf, !(*data & 1) ? "\u2588\u2588" : " "); data++; } @@ -929,6 +931,8 @@ cons_show_qrcode(const char* const text) buf[0] = '\0'; } win_println(console, THEME_DEFAULT, "", "%s", pad); + win_println(console, THEME_DEFAULT, "", ""); + win_println(console, THEME_DEFAULT, "", ""); free(pad); free(buf);