From 0c25cee86a28a52f7311cae06968398077cd75ed Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Sun, 8 Jan 2023 19:59:23 +0100 Subject: [PATCH 1/3] Modify checks in Akashis packet creation --- core/src/packet/packet_factory.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/packet/packet_factory.cpp b/core/src/packet/packet_factory.cpp index cf2f098..4584d6a 100644 --- a/core/src/packet/packet_factory.cpp +++ b/core/src/packet/packet_factory.cpp @@ -15,16 +15,23 @@ AOPacket *PacketFactory::createPacket(QString raw_packet) QString header; QStringList contents; - if (raw_packet.at(0) == '#' || raw_packet.contains("%") || raw_packet.isEmpty()) { + if (raw_packet.isEmpty()) { + qDebug() << "Empty packet received."; + return PacketFactory::createPacket("Unknown", {"Unknown"}); + } + + if (raw_packet.at(0) == '#' || raw_packet.contains("%")) { qDebug() << "FantaCrypt or otherwise invalid packet received"; return PacketFactory::createPacket("Unknown", {"Unknown"}); } QStringList packet_contents = raw_packet.split("#"); header = packet_contents[0]; - packet_contents.removeFirst(); // Remove header - packet_contents.removeLast(); // Remove anything trailing after delimiter + + if (!packet_contents.isEmpty()) { + packet_contents.removeLast(); // Remove anything trailing after delimiter + } contents = packet_contents; AOPacket *packet = PacketFactory::createPacket(header, contents); From 4d12bb90c046272b27fe59888616c29cf49bc307 Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Sun, 8 Jan 2023 20:01:35 +0100 Subject: [PATCH 2/3] Add test --- tests/unittest_aopacket/tst_unittest_aopacket.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unittest_aopacket/tst_unittest_aopacket.cpp b/tests/unittest_aopacket/tst_unittest_aopacket.cpp index e8d7743..d42a543 100644 --- a/tests/unittest_aopacket/tst_unittest_aopacket.cpp +++ b/tests/unittest_aopacket/tst_unittest_aopacket.cpp @@ -166,6 +166,9 @@ void Packet::createPacketFromString_data() QTest::newRow("Empty packet") << "" << "Unknown" << QStringList{"Unknown"}; + QTest::newRow("Bogus Packet - PR 328") << "ZZ#%@%#@^#@&^#@$^@&$^*@&$*@^$&*@$@^$&*@^$&#^&#@$#%" + << "Unknown" + << QStringList{"Unknown"}; } void Packet::createPacketFromString() From 86d12d174b2cc8819814b5c5e7c7065ffa15b472 Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Sun, 8 Jan 2023 20:03:15 +0100 Subject: [PATCH 3/3] *Perform blood sacrifice for clang* --- tests/unittest_aopacket/tst_unittest_aopacket.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unittest_aopacket/tst_unittest_aopacket.cpp b/tests/unittest_aopacket/tst_unittest_aopacket.cpp index d42a543..87d9ffe 100644 --- a/tests/unittest_aopacket/tst_unittest_aopacket.cpp +++ b/tests/unittest_aopacket/tst_unittest_aopacket.cpp @@ -167,8 +167,8 @@ void Packet::createPacketFromString_data() << "Unknown" << QStringList{"Unknown"}; QTest::newRow("Bogus Packet - PR 328") << "ZZ#%@%#@^#@&^#@$^@&$^*@&$*@^$&*@$@^$&*@^$&#^&#@$#%" - << "Unknown" - << QStringList{"Unknown"}; + << "Unknown" + << QStringList{"Unknown"}; } void Packet::createPacketFromString()