improve exceptions in case of corrupt packages close pipes after exception occoured to avoid lingering connections should fix #788

This commit is contained in:
JanEggers
2020-07-09 21:19:00 +02:00
parent 6a564a0c72
commit 33e4ec1943
10 changed files with 134 additions and 21 deletions
@@ -120,6 +120,14 @@ namespace MQTTnet.Formatter
{
if (receivedMqttPacket == null) throw new ArgumentNullException(nameof(receivedMqttPacket));
if (receivedMqttPacket.Body.Length < 7)
{
// 2 byte protocol name length
// at least 4 byte protocol name
// 1 byte protocol level
throw new MqttProtocolViolationException("Mqtt Connect packet must have at least 7 bytes");
}
var protocolName = receivedMqttPacket.Body.ReadStringWithLengthPrefix();
var protocolLevel = receivedMqttPacket.Body.ReadByte();