Ensure that packet headers get parsed correctly

bulletsim
Melanie 2011-07-27 08:35:19 +02:00
parent 4cdc8806fb
commit c4ffcd4b7d
1 changed files with 29 additions and 0 deletions

View File

@ -160,6 +160,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public Socket Server { get { return null; } } public Socket Server { get { return null; } }
private int m_malformedCount = 0; // Guard against a spamming attack
public LLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager) public LLUDPServer(IPAddress listenIP, ref uint port, int proxyPortOffsetParm, bool allow_alternate_port, IConfigSource configSource, AgentCircuitManager circuitManager)
: base(listenIP, (int)port) : base(listenIP, (int)port)
{ {
@ -612,6 +614,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
#region Decoding #region Decoding
if (buffer.DataLength < 7)
return; // Drop undersizd packet
int headerLen = 7;
if (buffer.Data[6] == 0xFF)
{
if (buffer.Data[7] == 0xFF)
headerLen = 10;
else
headerLen = 8;
}
if (buffer.DataLength < headerLen)
return; // Malformed header
try try
{ {
packet = Packet.BuildPacket(buffer.Data, ref packetEnd, packet = Packet.BuildPacket(buffer.Data, ref packetEnd,
@ -621,6 +638,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
catch (MalformedDataException) catch (MalformedDataException)
{ {
} }
catch (IndexOutOfRangeException)
{
return; // Drop short packet
}
catch(Exception e)
{
if (m_malformedCount < 100)
m_log.DebugFormat("[LLUDPSERVER]: Dropped malformed packet: " + e.ToString());
m_malformedCount++;
if ((m_malformedCount % 100000) == 0)
m_log.DebugFormat("[LLUDPSERVER]: Received {0} malformed packets so far, probable network attack.", m_malformedCount);
}
// Fail-safe check // Fail-safe check
if (packet == null) if (packet == null)