additional peer exceptions added

added a few cases where we should be raising peer exceptions when
delivered invalid frames from the server (per spec)
This commit is contained in:
Matt Broadstone 2014-06-19 13:36:11 -04:00
parent 81f9437495
commit cb52911bed
2 changed files with 35 additions and 20 deletions

View File

@ -170,9 +170,7 @@ void ClientPrivate::_q_readyRead()
const quint8 type = *(quint8*)&bufferData[0]; const quint8 type = *(quint8*)&bufferData[0];
const quint8 magic = *(quint8*)&bufferData[Frame::HEADER_SIZE + payloadSize]; const quint8 magic = *(quint8*)&bufferData[Frame::HEADER_SIZE + payloadSize];
if (magic != Frame::FRAME_END) { if (magic != Frame::FRAME_END) {
qAmqpDebug() << Q_FUNC_INFO << "FATAL: wrong end of frame"; close(UnexpectedFrameError, "wrong end of frame");
buffer.clear();
socket->close();
return; return;
} }
@ -200,6 +198,9 @@ void ClientPrivate::_q_readyRead()
if (frame.size() > frameMax) { if (frame.size() > frameMax) {
close(FrameError, "frame size too large"); close(FrameError, "frame size too large");
return; return;
} else if (frame.channel() <= 0) {
close(ChannelError, "channel number must be greater than zero");
return;
} }
foreach (Frame::ContentHandler *methodHandler, contentHandlerByChannel[frame.channel()]) foreach (Frame::ContentHandler *methodHandler, contentHandlerByChannel[frame.channel()])
@ -212,6 +213,9 @@ void ClientPrivate::_q_readyRead()
if (frame.size() > frameMax) { if (frame.size() > frameMax) {
close(FrameError, "frame size too large"); close(FrameError, "frame size too large");
return; return;
} else if (frame.channel() <= 0) {
close(ChannelError, "channel number must be greater than zero");
return;
} }
foreach (Frame::ContentBodyHandler *methodHandler, bodyHandlersByChannel[frame.channel()]) foreach (Frame::ContentBodyHandler *methodHandler, bodyHandlersByChannel[frame.channel()])
@ -219,10 +223,20 @@ void ClientPrivate::_q_readyRead()
} }
break; break;
case Frame::ftHeartbeat: case Frame::ftHeartbeat:
{
Frame::Method frame(streamB);
if (frame.channel() != 0) {
close(FrameError, "heartbeat must have channel id zero");
return;
}
qAmqpDebug("AMQP: Heartbeat"); qAmqpDebug("AMQP: Heartbeat");
}
break; break;
default: default:
qAmqpDebug() << "AMQP: Unknown frame type: " << type; qAmqpDebug() << "AMQP: Unknown frame type: " << type;
close(FrameError, "invalid frame type");
return;
} }
} else { } else {
break; break;

View File

@ -82,7 +82,8 @@ namespace Frame
/* /*
* @brief Definition implementation of TableField type * @brief Definition implementation of TableField type
* @detailed Define implementation TableField type in builtin Qt types. Key contains field name, value contains field data. * @detailed Define implementation TableField type in builtin Qt types.
* Key contains field name, value contains field data.
* It can by any type witch support serialization in AMQP types. * It can by any type witch support serialization in AMQP types.
*/ */
typedef QHash<QString, QVariant> TableField; typedef QHash<QString, QVariant> TableField;
@ -257,22 +258,22 @@ namespace Frame
* short short long long short remainder... * short short long long short remainder...
* @endcode * @endcode
* *
* | Property | Description | * | Property | Description |
* | ---------- | ----------- | * | ------------------ | -------------------------------------- |
* | cpContentType | MIME content type | * | cpContentType | MIME content type |
* | cpContentEncoding | MIME content encoding | * | cpContentEncoding | MIME content encoding |
* | cpHeaders | message header field table | * | cpHeaders | message header field table |
* | cpDeliveryMode| nonpersistent (1) or persistent (2) | * | cpDeliveryMode | nonpersistent (1) or persistent (2) |
* | cpPriority | message priority, 0 to 9 | * | cpPriority | message priority, 0 to 9 |
* | cpCorrelationId | application correlation identifier | * | cpCorrelationId | application correlation identifier |
* | cpReplyTo | address to reply to | * | cpReplyTo | address to reply to |
* | cpExpiration | message expiration specification | * | cpExpiration | message expiration specification |
* | cpMessageId | application message identifier | * | cpMessageId | application message identifier |
* | cpTimestamp | message timestamp | * | cpTimestamp | message timestamp |
* | cpType | message type name | * | cpType | message type name |
* | cpUserId | creating user id | * | cpUserId | creating user id |
* | cpAppId | creating application id | * | cpAppId | creating application id |
* | cpClusterID| cluster ID | * | cpClusterID | cluster ID |
* *
* Default property: * Default property:
* @sa setProperty * @sa setProperty