Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/SmtpServer.Tests/SmtpParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,24 @@ public void CanMakeProxyTcp6()
Assert.Equal(16789, ((ProxyCommand)command).DestinationEndpoint.Port);
}

[Theory]
[InlineData("PROXY TCP5 192.168.1.1 192.168.1.2 1234 16789")]
[InlineData("PROXY TCP46 192.168.1.1 192.168.1.2 1234 16789")]
[InlineData("PROXY TCPA 192.168.1.1 192.168.1.2 1234 16789")]
public void CanNotMakeProxyWithInvalidTcpVersion(string input)
{
// arrange
var reader = CreateReader(input);

// act
var result = Parser.TryMakeProxy(ref reader, out var command, out var errorResponse);

// assert
Assert.False(result);
Assert.Null(command);
Assert.Null(errorResponse);
}

[Fact]
public void CanMakeAtom()
{
Expand Down
4 changes: 2 additions & 2 deletions src/SmtpServer/Protocol/SmtpParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ public bool TryMakeTcp4Proxy(ref TokenReader reader, out SmtpCommand command)
}

var token = reader.Take();
if (token.Kind != TokenKind.Number && token.Text[0] != '4')
if (token.Kind != TokenKind.Number || token.Text.Length != 1 || token.Text[0] != '4')
{
return false;
}
Expand All @@ -869,7 +869,7 @@ public bool TryMakeTcp6Proxy(ref TokenReader reader, out SmtpCommand command)
}

var token = reader.Take();
if (token.Kind != TokenKind.Number && token.Text[0] != '6')
if (token.Kind != TokenKind.Number || token.Text.Length != 1 || token.Text[0] != '6')
{
return false;
}
Expand Down