Skip to content

Commit 601768c

Browse files
committed
DTLS: Sanity check on return value from DtlsTransport.Receive
1 parent 0b52881 commit 601768c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

crypto/src/tls/DtlsRecordLayer.cs

+9-7
Original file line numberDiff line numberDiff line change
@@ -654,25 +654,27 @@ private int ReceiveDatagram(byte[] buf, int off, int len, int waitMillis)
654654
{
655655
try
656656
{
657-
return m_transport.Receive(buf, off, len, waitMillis);
657+
// NOTE: the buffer is sized to support m_transport.GetReceiveLimit().
658+
int received = m_transport.Receive(buf, off, len, waitMillis);
659+
660+
// Check the transport returned a sensible value, otherwise discard the datagram.
661+
if (received <= len)
662+
return received;
658663
}
659664
catch (TlsTimeoutException)
660665
{
661-
return -1;
662666
}
663-
catch (SocketException e)
667+
catch (SocketException e) when (TlsUtilities.IsTimeout(e))
664668
{
665-
if (TlsUtilities.IsTimeout(e))
666-
return -1;
667-
668-
throw;
669669
}
670670
// TODO[tls-port] Can we support interrupted IO on .NET?
671671
//catch (InterruptedIOException e)
672672
//{
673673
// e.bytesTransferred = 0;
674674
// throw;
675675
//}
676+
677+
return -1;
676678
}
677679

678680
// TODO Include 'currentTimeMillis' as an argument, use with Timeout, resetHeartbeat

0 commit comments

Comments
 (0)