Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mDNS parser: skip a 'Record' on parse error #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test: captured from Python zeroconf
Add a real-life UDP packed data captured from Python zeroconf module.

The current 'master' (0ca8011) incorrectly determines the end of NSEC
record, causing next 'A' record unparsed.
  • Loading branch information
asashnov committed Apr 17, 2022
commit 289283954e252ace888d52c2b00eec34c5a0d3fc
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(TESTS
TestBrowser
TestCache
TestDns
TestFromPacket
TestHostname
TestProber
TestProvider
Expand Down
58 changes: 58 additions & 0 deletions tests/TestFromPacket.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <QTest>

#include <qmdnsengine/dns.h>
#include <qmdnsengine/record.h>
#include <qmdnsengine/message.h>

unsigned char b0[] = {
0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04,
0x10, 0x5f, 0x75, 0x6e, 0x69, 0x70, 0x72, 0x6f, 0x2d, 0x6c, 0x61, 0x70,
0x74, 0x69, 0x6d, 0x65, 0x72, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x6c,
0x6f, 0x63, 0x61, 0x6c, 0x00, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x00, 0x11,
0x94, 0x00, 0x0e, 0x0b, 0x75, 0x6e, 0x69, 0x67, 0x6f, 0x2d, 0x31, 0x32,
0x33, 0x34, 0x35, 0xc0, 0x0c, 0xc0, 0x33, 0x00, 0x21, 0x80, 0x01, 0x00,
0x00, 0x00, 0x78, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x90, 0x0b,
0x75, 0x6e, 0x69, 0x67, 0x6f, 0x2d, 0x31, 0x32, 0x33, 0x34, 0x35, 0xc0,
0x22, 0xc0, 0x53, 0x00, 0x2f, 0x80, 0x01, 0x00, 0x00, 0x11, 0x94, 0x00,
0x0a, 0xc0, 0x53, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0xc0,
0x53, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x04, 0xc0,
0xa8, 0x32, 0x45, 0xc0, 0x33, 0x00, 0x10, 0x80, 0x01, 0x00, 0x00, 0x11,
0x94, 0x00, 0x3d, 0x10, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x3d, 0x55, 0x6e,
0x69, 0x70, 0x72, 0x6f, 0x20, 0x41, 0x70, 0x73, 0x07, 0x44, 0x72, 0x69,
0x76, 0x65, 0x72, 0x3d, 0x0f, 0x4d, 0x6f, 0x64, 0x65, 0x6c, 0x3d, 0x55,
0x6e, 0x69, 0x47, 0x6f, 0x20, 0x4f, 0x6e, 0x65, 0x13, 0x73, 0x65, 0x72,
0x69, 0x61, 0x6c, 0x2d, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x3d, 0x31,
0x32, 0x33, 0x34, 0x35
};


class TestFromPacket : public QObject
{
Q_OBJECT

private Q_SLOTS:

void testParseB0();
};



void TestFromPacket::testParseB0()
{
/* This code mimics
* void ServerPrivate::onReadyRead()
* ...
* socket->readDatagram(packet.data(), packet.size(), &address, &port);
*/

QByteArray packet = QByteArray::fromRawData(
(const char *)b0, sizeof(b0));

QMdnsEngine::Message message;

QVERIFY(fromPacket(packet, message));
}


QTEST_MAIN(TestFromPacket)
#include "TestFromPacket.moc"