From dec9ef72d32782db2df56a5fba036dd0ca65ee5d Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Mon, 30 Jun 2014 18:42:39 -0400 Subject: [PATCH] added test for invalid routing keys also added a debug message for attempts to write shortstr's greater than acceptable length. --- src/amqp_frame.cpp | 7 ++++++- tests/auto/qamqpqueue/tst_qamqpqueue.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/amqp_frame.cpp b/src/amqp_frame.cpp index a404574..1b5e03c 100644 --- a/src/amqp_frame.cpp +++ b/src/amqp_frame.cpp @@ -6,6 +6,8 @@ #include #include +#include "amqp_global.h" + using namespace QAMQP; using namespace QAMQP::Frame; @@ -342,7 +344,6 @@ void Frame::print(const TableField &f) void Frame::writeField(qint8 valueType, QDataStream &s, const QVariant &value, bool withType) { - QByteArray tmp; if (withType) s << valueType; @@ -390,6 +391,10 @@ void Frame::writeField(qint8 valueType, QDataStream &s, const QVariant &value, b case 's': { QString str = value.toString(); + if (str.length() >= 256) { + qAmqpDebug() << Q_FUNC_INFO << "invalid shortstr length: " << str.length(); + } + s << quint8(str.length()); s.writeRawData(str.toLatin1().data(), str.length()); } diff --git a/tests/auto/qamqpqueue/tst_qamqpqueue.cpp b/tests/auto/qamqpqueue/tst_qamqpqueue.cpp index 28365d6..3ccac9c 100644 --- a/tests/auto/qamqpqueue/tst_qamqpqueue.cpp +++ b/tests/auto/qamqpqueue/tst_qamqpqueue.cpp @@ -40,6 +40,7 @@ private Q_SLOTS: void defineQos(); void invalidQos(); void qos(); + void invalidRoutingKey(); private: void declareQueueAndVerifyConsuming(Queue *queue); @@ -468,5 +469,14 @@ void tst_QAMQPQueue::qos() QCOMPARE(messageReceivedCount, messageCount); } +void tst_QAMQPQueue::invalidRoutingKey() +{ + QString routingKey = QString("%1").arg('1', 256, QLatin1Char('0')); + Queue *queue = client->createQueue(routingKey); + queue->declare(); + QVERIFY(waitForSignal(client.data(), SIGNAL(error(QAMQP::Error)))); + QCOMPARE(client->error(), QAMQP::FrameError); +} + QTEST_MAIN(tst_QAMQPQueue) #include "tst_qamqpqueue.moc"