Skip to content
This repository was archived by the owner on Apr 17, 2021. It is now read-only.

Commit 547e292

Browse files
Matt VinallMatt Vinall
authored andcommitted
fix Deserialise infinite loop for invalid record
- also bump version Signed-off-by: Matt Vinall <[email protected]>
1 parent a741673 commit 547e292

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DTLS_VERSION:=1.0.19
1+
DTLS_VERSION:=1.0.21
22

33
.PHONY: all
44
all: src/DTLS.Net/bin/Release/DTLS.Net.$(DTLS_VERSION).nupkg

src/DTLS.Net/Records/DTLSRecord.cs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ All rights reserved.
44
55
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
66
following conditions are met:
7-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8-
following disclaimer.
9-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10-
following disclaimer in the documentation and/or other materials provided with the distribution.
11-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
12-
products derived from this software without specific prior written permission.
7+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8+
following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10+
following disclaimer in the documentation and/or other materials provided with the distribution.
11+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
12+
products derived from this software without specific prior written permission.
1313
1414
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
15-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
15+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1717
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19-
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
18+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
2020
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2121
***********************************************************************************************************************/
2222

@@ -36,8 +36,8 @@ namespace DTLS
3636
internal class DTLSRecord
3737
{
3838
public static Version DefaultVersion = new Version(1, 0);
39-
public static Version Version1_0 = new Version(1, 0);
40-
public static Version Version1_2 = new Version(1, 2);
39+
public static Version Version1_0 = new Version(1, 0);
40+
public static Version Version1_2 = new Version(1, 2);
4141

4242
public const int RECORD_OVERHEAD = 13;
4343

@@ -58,7 +58,7 @@ internal class DTLSRecord
5858
// opaque fragment[DTLSPlaintext.length];
5959
//} DTLSPlaintext;
6060

61-
public TRecordType RecordType
61+
public TRecordType RecordType
6262
{
6363
get { return _RecordType; }
6464
set { _RecordType = value; }
@@ -85,7 +85,7 @@ public long SequenceNumber
8585
public byte[] Fragment
8686
{
8787
get { return _Fragment; }
88-
set
88+
set
8989
{
9090
_Fragment = value;
9191
if (_Fragment != null)
@@ -108,6 +108,7 @@ public static DTLSRecord Deserialise(Stream stream)
108108
{
109109
DTLSRecord result = new DTLSRecord();
110110
result._RecordType = (TRecordType)stream.ReadByte();
111+
// could check here for a valid type, and bail out if invalid
111112
result._Version = new Version(255 - stream.ReadByte(), 255 - stream.ReadByte());
112113
result._Epoch = NetworkByteOrderConverter.ToUInt16(stream);
113114
result._SequenceNumber = NetworkByteOrderConverter.ToInt48(stream);
@@ -116,10 +117,18 @@ public static DTLSRecord Deserialise(Stream stream)
116117
{
117118
result._Fragment = new byte[result._Length];
118119
int length = stream.Read(result._Fragment, 0, result._Length);
119-
while (length < result._Length)
120-
{
121-
length += stream.Read(result._Fragment, length, result._Length - length);
122-
}
120+
while (length < result._Length)
121+
{
122+
int bytesRead = stream.Read(result._Fragment, length, result._Length - length);
123+
if (bytesRead > 0)
124+
{
125+
length += bytesRead;
126+
}
127+
else
128+
{
129+
break;
130+
}
131+
}
123132
}
124133
return result;
125134
}

src/DTLS.Net/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"version": "1.0.19-*",
2+
"version": "1.0.21-*",
33
"title": "DTLS.Net",
4-
"description": "DTLS.Net Class Library",
4+
"description": "DTLS.Net Class Library",
55
"authors": [ "Delme Thomas" ],
66
"packOptions": {
77
"owners": [ "Imagination Technologies Limited" ],

0 commit comments

Comments
 (0)