Don't accept message if number of forwarding tokens is too high.

This commit is contained in:
Felix Ableitner 2016-07-01 21:50:38 +02:00
parent 5310c34218
commit 45bb01cd8e
4 changed files with 10 additions and 6 deletions

View file

@ -10,6 +10,8 @@ object AbstractHeader {
val InitialForwardingTokens = 3
val MaxForwardingTokens = 6
val Version = 0
private[header] val Length = 10 + 2 * Address.Length

View file

@ -24,6 +24,8 @@ object MessageHeader {
throw new ReadMessageException("Failed to parse message with unsupported version " + version)
val protocolType = BufferUtils.getUnsignedByte(b)
val tokens = BufferUtils.getUnsignedByte(b)
if (tokens > AbstractHeader.MaxForwardingTokens)
throw new ReadMessageException(s"Received message with too many forwarding tokens ($tokens tokens)")
val hopCount = BufferUtils.getUnsignedByte(b)
val length = BufferUtils.getUnsignedInt(b)

View file

@ -10,16 +10,16 @@ import org.junit.Assert._
object ContentHeaderTest {
val h1 = new ContentHeader(AddressTest.a1, AddressTest.a2, 1234,
Text.Type, Some(123), Some(new GregorianCalendar(1970, 1, 1).getTime), 5)
Text.Type, Some(123), Some(new GregorianCalendar(1970, 1, 1).getTime), 3)
val h2 = new ContentHeader(AddressTest.a1, AddressTest.a3,
30000, Text.Type, Some(8765), Some(new GregorianCalendar(2014, 6, 10).getTime), 20)
30000, Text.Type, Some(8765), Some(new GregorianCalendar(2014, 6, 10).getTime), 2)
val h3 = new ContentHeader(AddressTest.a4, AddressTest.a2,
250, Text.Type, Some(77), Some(new GregorianCalendar(2020, 11, 11).getTime), 123)
250, Text.Type, Some(77), Some(new GregorianCalendar(2020, 11, 11).getTime), 1)
val h4 = new ContentHeader(Address.Null, Address.Broadcast,
ContentHeader.SeqNumRange.last, 0, Some(0xffff), Some(new Date(0L)), 0xff)
ContentHeader.SeqNumRange.last, 0, Some(0xffff), Some(new Date(0L)), 6)
val h5 = new ContentHeader(Address.Broadcast, Address.Null,
0, 0xff, Some(0), Some(new Date(0xffffffffL)), 0)

View file

@ -7,11 +7,11 @@ import org.junit.Assert._
object MessageHeaderTest {
val h1 = new MessageHeader(ContentHeader.ContentMessageType, AddressTest.a1, AddressTest.a2, 1234,
val h1 = new MessageHeader(ContentHeader.ContentMessageType, AddressTest.a1, AddressTest.a2, 3,
0)
val h2 = new MessageHeader(ContentHeader.ContentMessageType, Address.Null, Address.Broadcast,
ContentHeader.SeqNumRange.last, 0xff, 3)
ContentHeader.SeqNumRange.last, 6, 3)
val h3 = new MessageHeader(ContentHeader.ContentMessageType, Address.Broadcast, Address.Null, 0, 3)