Browse Source

chatgui: fix corrupted channel_id from non-null-terminated binary protocol

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.
topo_upd
Evgeny 2 months ago
parent
commit
83ca0c65a4
  1. 7
      tools/chatgui/src/mainwindow.cpp
  2. 2
      tools/chatgui/src/mainwindow.h

7
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())

2
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);

Loading…
Cancel
Save