diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-02-05 12:13:31 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2024-02-05 12:13:31 +0700 |
commit | 601768c817158262c45ace6df6ae91cdc4d18541 (patch) | |
tree | 1f9a5537178060f7bda892a752b7a217905eb035 | |
parent | Add retries to make signing more reliable (diff) | |
download | BouncyCastle.NET-ed25519-601768c817158262c45ace6df6ae91cdc4d18541.tar.xz |
DTLS: Sanity check on return value from DtlsTransport.Receive
-rw-r--r-- | crypto/src/tls/DtlsRecordLayer.cs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/crypto/src/tls/DtlsRecordLayer.cs b/crypto/src/tls/DtlsRecordLayer.cs index fe3b58d41..7f5acc40f 100644 --- a/crypto/src/tls/DtlsRecordLayer.cs +++ b/crypto/src/tls/DtlsRecordLayer.cs @@ -654,18 +654,18 @@ namespace Org.BouncyCastle.Tls { 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) @@ -673,6 +673,8 @@ namespace Org.BouncyCastle.Tls // e.bytesTransferred = 0; // throw; //} + + return -1; } // TODO Include 'currentTimeMillis' as an argument, use with Timeout, resetHeartbeat |