From 83ca0c65a44a51d0e45de2ab67ae42097cd60ee5 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Fri, 24 Jul 2026 03:33:14 +0300 Subject: [PATCH] chatgui: fix corrupted channel_id from non-null-terminated binary protocol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QString::fromUtf8(ch_id) read past length-prefixed string, capturing garbage. Use fromUtf8(ch_id, ch_id_len) — length already available from bridge but was unused. Messages now appear on refresh and unread badge correctly matches channel. --- tools/chatgui/src/mainwindow.cpp | 7 +++---- tools/chatgui/src/mainwindow.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/chatgui/src/mainwindow.cpp b/tools/chatgui/src/mainwindow.cpp index 39493aaa..1e9d93d2 100644 --- a/tools/chatgui/src/mainwindow.cpp +++ b/tools/chatgui/src/mainwindow.cpp @@ -32,9 +32,8 @@ extern "C" { static MainWindow* s_mainWindow = nullptr; static void onMsgReceivedCallback(const char* ch_id, int ch_id_len, uint64_t author) { - Q_UNUSED(ch_id_len); if (s_mainWindow) - s_mainWindow->onMessageReceived(ch_id, author); + s_mainWindow->onMessageReceived(ch_id, ch_id_len, author); } static void onChannelUpdatedCallback(const char* ch_id, int ch_id_len) { @@ -334,8 +333,8 @@ void MainWindow::showSettings() { dlg.exec(); } -void MainWindow::onMessageReceived(const char* ch_id, uint64_t author) { - QString cid = QString::fromUtf8(ch_id); +void MainWindow::onMessageReceived(const char* ch_id, int ch_id_len, uint64_t author) { + QString cid = QString::fromUtf8(ch_id, ch_id_len); DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "MainWindow::onMessageReceived ch=%s author=%llu cur=%s", qPrintable(cid), (unsigned long long)author, qPrintable(m_currentChannelId)); if (m_db && author != m_db->myNodeId()) diff --git a/tools/chatgui/src/mainwindow.h b/tools/chatgui/src/mainwindow.h index 3b7ee783..814f3a2b 100644 --- a/tools/chatgui/src/mainwindow.h +++ b/tools/chatgui/src/mainwindow.h @@ -31,7 +31,7 @@ private slots: void showSettings(); public: - void onMessageReceived(const char* ch_id, uint64_t author); + void onMessageReceived(const char* ch_id, int ch_id_len, uint64_t author); void onMembersChanged(const char* ch_id); void onAutoConnectStatus(uint8_t status, uint16_t total, uint16_t totalNodes, uint16_t connected); void onChannelPeersOnline(const char* ch_id, int ch_id_len, uint16_t online);