mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-19 19:13:11 +08:00
Fix infinite loop that can occur when the client closes the connection before sending the complete packet body.
This commit is contained in:
@@ -137,6 +137,12 @@ namespace MQTTnet.Adapter
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
var readBytesCount = await stream.ReadAsync(body, offset, body.Length - offset, cancellationToken).ConfigureAwait(false);
|
var readBytesCount = await stream.ReadAsync(body, offset, body.Length - offset, cancellationToken).ConfigureAwait(false);
|
||||||
|
// Check if the client closed the connection before sending the full body.
|
||||||
|
if (readBytesCount == 0)
|
||||||
|
{
|
||||||
|
throw new MqttCommunicationException("Connection closed while reading remaining packet body.");
|
||||||
|
}
|
||||||
|
|
||||||
offset += readBytesCount;
|
offset += readBytesCount;
|
||||||
} while (offset < header.BodyLength);
|
} while (offset < header.BodyLength);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user