Skip to content

Commit

Permalink
DhcpOptionsBuffer - EnumerateCorruptRadiusAttributeUnderflow
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Jan 19, 2020
1 parent 878fad5 commit 675bdca
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions DhcpServer.Test/DhcpOptionsBufferTest.cs
Expand Up @@ -144,5 +144,42 @@ public void EnumerateCorruptRadiusAttribute()

span.Slice(0, charsWritten).ToString().Should().Be(ExpectedRadiusAttributes);
}

[TestMethod]
public void EnumerateCorruptRadiusAttributeUnderflow()
{
const string ExpectedRadiusAttributes =
@"UserName={61}
None={FE010A00000000}
";
Memory<byte> options = new Memory<byte>(new byte[17]);
DhcpOptionsBuffer buffer = new DhcpOptionsBuffer(options, Memory<byte>.Empty, Memory<byte>.Empty);
DhcpOption option = buffer.Slice(0, DhcpOptionTag.RelayAgentInformation, 12);
int i = 0;
option.Data.Span[i++] = (byte)DhcpRelayAgentSubOptionCode.RadiusAttributes;
option.Data.Span[i++] = 10; // sub-option #1 length
option.Data.Span[i++] = (byte)RadiusAttributeType.UserName;
option.Data.Span[i++] = 3; // attribute #1 length
option.Data.Span[i++] = (byte)'a'; // attribute #1 data
option.Data.Span[i++] = 254; // attribute #2 code
option.Data.Span[i++] = 1; // attribute #2 length (BAD -> will underflow)
option.Data.Span[i++] = 10; // attribute #2 data
Span<char> span = new Span<char>(new char[100]);

int charsWritten = 0;
foreach (DhcpRelayAgentInformationSubOption subOption in option.RelayAgentInformation())
{
foreach (RadiusAttribute attribute in subOption.RadiusAttributes())
{
Span<char> destination = span.Slice(charsWritten);
attribute.TryFormat(destination, out int c).Should().BeTrue();
destination[c++] = '\r';
destination[c++] = '\n';
charsWritten += c;
}
}

span.Slice(0, charsWritten).ToString().Should().Be(ExpectedRadiusAttributes);
}
}
}

0 comments on commit 675bdca

Please sign in to comment.