From 8419bf2a04e45720ee7662a481a5cc386acb9157 Mon Sep 17 00:00:00 2001
From: Eric House <eehouse@eehouse.org>
Date: Fri, 28 Jun 2013 18:48:57 -0700
Subject: [PATCH] close socket if length == 0 -- protocol violation or network
 error

---
 xwords4/relay/udpqueue.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/xwords4/relay/udpqueue.cpp b/xwords4/relay/udpqueue.cpp
index d06d29e42..081210b33 100644
--- a/xwords4/relay/udpqueue.cpp
+++ b/xwords4/relay/udpqueue.cpp
@@ -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