From 1625c42e384f8145f2e83b3c6606a85e36209825 Mon Sep 17 00:00:00 2001 From: srcejon Date: Thu, 20 Jun 2024 22:00:15 +0100 Subject: [PATCH 1/2] AIS: Validate message length. Fixes #2125 --- plugins/channelrx/demodais/aisdemod.cpp | 24 ++++++++++++---------- plugins/channelrx/demodais/aisdemodgui.cpp | 3 +++ plugins/channelrx/demodais/readme.md | 2 +- plugins/feature/ais/aisgui.cpp | 4 +++- sdrbase/util/ais.cpp | 4 ++++ 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/plugins/channelrx/demodais/aisdemod.cpp b/plugins/channelrx/demodais/aisdemod.cpp index de40b6787..9149835f5 100644 --- a/plugins/channelrx/demodais/aisdemod.cpp +++ b/plugins/channelrx/demodais/aisdemod.cpp @@ -211,18 +211,20 @@ bool AISDemod::handleMessage(const Message& cmd) // Decode the message ais = AISMessage::decode(report.getMessage()); + if (ais) + { + m_logStream << report.getDateTime().date().toString() << "," + << report.getDateTime().time().toString() << "," + << report.getMessage().toHex() << "," + << QString("%1").arg(ais->m_mmsi, 9, 10, QChar('0')) << "," + << ais->getType() << "," + << "\"" << ais->toString() << "\"" << "," + << "\"" << ais->toNMEA() << "\"" << "," + << report.getSlot() << "," + << report.getSlots() << "\n"; - m_logStream << report.getDateTime().date().toString() << "," - << report.getDateTime().time().toString() << "," - << report.getMessage().toHex() << "," - << QString("%1").arg(ais->m_mmsi, 9, 10, QChar('0')) << "," - << ais->getType() << "," - << "\"" << ais->toString() << "\"" << "," - << "\"" << ais->toNMEA() << "\"" << "," - << report.getSlot() << "," - << report.getSlots() << "\n"; - - delete ais; + delete ais; + } } return true; diff --git a/plugins/channelrx/demodais/aisdemodgui.cpp b/plugins/channelrx/demodais/aisdemodgui.cpp index ad02fc958..b47ebbf36 100644 --- a/plugins/channelrx/demodais/aisdemodgui.cpp +++ b/plugins/channelrx/demodais/aisdemodgui.cpp @@ -422,6 +422,9 @@ void AISDemodGUI::messageReceived(const QByteArray& message, const QDateTime& da // Decode the message ais = AISMessage::decode(message); + if (!ais) { + return; + } // Is scroll bar at bottom QScrollBar *sb = ui->messages->verticalScrollBar(); diff --git a/plugins/channelrx/demodais/readme.md b/plugins/channelrx/demodais/readme.md index 470f54d21..4980b29e9 100644 --- a/plugins/channelrx/demodais/readme.md +++ b/plugins/channelrx/demodais/readme.md @@ -6,7 +6,7 @@ This plugin can be used to demodulate AIS (Automatic Identification System) mess AIS is broadcast globally on 25kHz channels at 161.975MHz and 162.025MHz, with other frequencies being used regionally or for special purposes. This demodulator is single channel, so if you wish to decode multiple channels simultaneously, you will need to add one AIS demodulator per frequency. As most AIS messages are on 161.975MHz and 162.025MHz, you can set the center frequency as 162MHz, with a sample rate of 100k+Sa/s, with one AIS demod with an input offset -25kHz and another at +25kHz. -The AIS demodulators can send received messages to the [AIS feature](../../feature/ais/readme.md), which displays a table combining the latest data for vessels amalgamated from multiple demodulators and sends their positions to the [Map Feature](../../feature/map/readme.ais) for display in 2D or 3D. +The AIS demodulators can send received messages to the [AIS feature](../../feature/ais/readme.md), which displays a table combining the latest data for vessels amalgamated from multiple demodulators and sends their positions to the [Map Feature](../../feature/map/readme.md) for display in 2D or 3D. AIS uses GMSK/FM modulation at a baud rate of 9,600, with a modulation index of 0.5. The demodulator works at a sample rate of 57,600Sa/s. diff --git a/plugins/feature/ais/aisgui.cpp b/plugins/feature/ais/aisgui.cpp index 6927e2733..d240c2355 100644 --- a/plugins/feature/ais/aisgui.cpp +++ b/plugins/feature/ais/aisgui.cpp @@ -152,7 +152,9 @@ bool AISGUI::handleMessage(const Message& message) // Decode the message AISMessage *ais = AISMessage::decode(report.getPacket()); // Update table - updateVessels(ais, report.getDateTime()); + if (ais) { + updateVessels(ais, report.getDateTime()); + } } return false; diff --git a/sdrbase/util/ais.cpp b/sdrbase/util/ais.cpp index 0f282a971..1163c1103 100644 --- a/sdrbase/util/ais.cpp +++ b/sdrbase/util/ais.cpp @@ -179,6 +179,10 @@ QString AISMessage::typeToString(quint8 type) AISMessage* AISMessage::decode(const QByteArray ba) { + if (ba.size() < 1) { + return nullptr; + } + int id = (ba[0] >> 2) & 0x3f; if ((id == 1) || (id == 2) || (id == 3)) { From 5f0fc8fbf72250de9f4d699ad1199b9b1d46334a Mon Sep 17 00:00:00 2001 From: srcejon Date: Thu, 20 Jun 2024 22:30:39 +0100 Subject: [PATCH 2/2] Configurations dialog: Fix slot names. Sort configs when dialog first opened. --- sdrgui/gui/configurationsdialog.cpp | 6 ++++-- sdrgui/gui/configurationsdialog.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sdrgui/gui/configurationsdialog.cpp b/sdrgui/gui/configurationsdialog.cpp index 4e5c09b20..edbc21068 100644 --- a/sdrgui/gui/configurationsdialog.cpp +++ b/sdrgui/gui/configurationsdialog.cpp @@ -60,6 +60,8 @@ void ConfigurationsDialog::populateTree() return; } + sortConfigurations(); + QList::const_iterator it = m_configurations->begin(); int middleIndex = m_configurations->size() / 2; QTreeWidgetItem *treeItem; @@ -445,14 +447,14 @@ void ConfigurationsDialog::on_configurationImport_clicked() } } -void ConfigurationsDialog::on_configurationTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) +void ConfigurationsDialog::on_configurationsTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) { (void) current; (void) previous; updateConfigurationControls(); } -void ConfigurationsDialog::on_configurationTree_itemActivated(QTreeWidgetItem *item, int column) +void ConfigurationsDialog::on_configurationsTree_itemActivated(QTreeWidgetItem *item, int column) { (void) item; (void) column; diff --git a/sdrgui/gui/configurationsdialog.h b/sdrgui/gui/configurationsdialog.h index 4bd3ea813..a6e5a2a42 100644 --- a/sdrgui/gui/configurationsdialog.h +++ b/sdrgui/gui/configurationsdialog.h @@ -69,8 +69,8 @@ private slots: void on_configurationImport_clicked(); void on_configurationDelete_clicked(); void on_configurationLoad_clicked(); - void on_configurationTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); - void on_configurationTree_itemActivated(QTreeWidgetItem *item, int column); + void on_configurationsTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); + void on_configurationsTree_itemActivated(QTreeWidgetItem *item, int column); void accept() override; signals: