close socket if length == 0 -- protocol violation or network error

This commit is contained in:
Eric House 2013-06-28 18:48:57 -07:00
parent 0a794f390f
commit 8419bf2a04

View file

@ -103,6 +103,7 @@ bool
UdpQueue::handle( const AddrInfo* addr, QueueCallback cb )
{
PartialPacket* packet;
bool success = true;
int sock = addr->socket();
@ -122,10 +123,11 @@ UdpQueue::handle( const AddrInfo* addr, QueueCallback cb )
if ( packet->readSoFar() < sizeof( packet->m_len ) ) {
if ( packet->readAtMost( sizeof(packet->m_len) - packet->readSoFar() ) ) {
packet->m_len = ntohs(*(unsigned short*)packet->data());
success = 0 < packet->m_len;
}
}
if ( packet->readSoFar() >= sizeof( packet->m_len ) ) {
if ( success && packet->readSoFar() >= sizeof( packet->m_len ) ) {
assert( 0 < packet->m_len );
int leftToRead =
packet->m_len - (packet->readSoFar() - sizeof(packet->m_len));
@ -137,7 +139,8 @@ UdpQueue::handle( const AddrInfo* addr, QueueCallback cb )
}
}
return NULL == packet || packet->stillGood();
success = success && (NULL == packet || packet->stillGood());
return success;
}
void