Skip to content

Commit

Permalink
DTLS: Sanity check on return value from DtlsTransport.Receive
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdettman committed Feb 5, 2024
1 parent 0b52881 commit 601768c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions crypto/src/tls/DtlsRecordLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,25 +654,27 @@ private int ReceiveDatagram(byte[] buf, int off, int len, int waitMillis)
{
try
{
return m_transport.Receive(buf, off, len, waitMillis);
// NOTE: the buffer is sized to support m_transport.GetReceiveLimit().
int received = m_transport.Receive(buf, off, len, waitMillis);

// Check the transport returned a sensible value, otherwise discard the datagram.
if (received <= len)
return received;
}
catch (TlsTimeoutException)
{
return -1;
}
catch (SocketException e)
catch (SocketException e) when (TlsUtilities.IsTimeout(e))
{
if (TlsUtilities.IsTimeout(e))
return -1;

throw;
}
// TODO[tls-port] Can we support interrupted IO on .NET?
//catch (InterruptedIOException e)
//{
// e.bytesTransferred = 0;
// throw;
//}

return -1;
}

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

0 comments on commit 601768c

Please sign in to comment.