- Highlight more undefined behavior of net protocol
authorunc0rr
Sat, 18 Aug 2007 12:05:29 +0000
changeset 573 e0cf483e68d6
parent 572 302ad5c3836d
child 574 1cafd9eb1a21
- Highlight more undefined behavior of net protocol - Fix calling QList::operator[] with invalid index - Fix wrong 'HHNUM' message being sent to all clients along with 'CONFIG_PARAM HHNUM' message
QTfrontend/netconnectedclient.cpp
QTfrontend/newnetclient.cpp
--- a/QTfrontend/netconnectedclient.cpp	Thu Aug 16 15:16:56 2007 +0000
+++ b/QTfrontend/netconnectedclient.cpp	Sat Aug 18 12:05:29 2007 +0000
@@ -97,7 +97,11 @@
     return;
   }
 
-  if(client_nick=="") return;
+  if(client_nick=="")
+  {
+  	qWarning(QString("Net: Message from unnamed client: '%1'").arg(msg).toAscii().data());
+  	return;
+  }
 
   if (lst[0]=="START:") {
     readyToStart=true;
@@ -126,6 +130,7 @@
     // create CONFIG_PARAM to save HHNUM at server from lst
     lst=QStringList("CONFIG_PARAM") << confstr << lst[3];
     m_hwserver->sendOthers(this, lst.join(QString(delimeter)));
+    return;
   }
 
   if(lst[0]=="CONFIG_PARAM") {
@@ -133,7 +138,7 @@
       qWarning((QString("Net: Bad 'CONFIG_PARAM' message: ")+msg).toAscii().data());
       return;
     }
-    
+
     if(!m_hwserver->isChiefClient(this))
     {
       return; // permission denied
--- a/QTfrontend/newnetclient.cpp	Thu Aug 16 15:16:56 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Sat Aug 18 12:05:29 2007 +0000
@@ -159,7 +159,11 @@
 
   if (lst[0] == "CHAT_STRING") {
     lst.pop_front();
-    if(lst.size() < 2) return;
+    if(lst.size() < 2)
+    {
+	  qWarning("Net: Empty CHAT_STRING message");
+	  return;
+    }
     emit chatStringFromNet(lst);
     return;
   }
@@ -171,7 +175,11 @@
   }
 
   if (lst[0] == "REMOVETEAM:") {
-    if(lst.size()<3) return;
+    if(lst.size() < 3)
+    {
+      qWarning("Net: Bad REMOVETEAM message");
+      return;
+    }
     m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1], lst[2].toUInt()));
     return;
   }
@@ -183,13 +191,21 @@
   }
 
   if(lst[0]=="JOINED") {
-    if(lst.size()<2) return;
+    if(lst.size() < 2)
+    {
+      qWarning("Net: Bad JOINED message");
+      return;
+    }
     emit nickAdded(lst[1]);
     return;
   }
 
   if(lst[0]=="LEFT") {
-    if(lst.size()<2) return;
+    if(lst.size() < 2)
+    {
+      qWarning("Net: Bad LEFT message");
+      return;
+    }
     emit nickRemoved(lst[1]);
     return;
   }
@@ -207,7 +223,11 @@
 
   if (lst[0] == "CONFIGURED") {
     lst.pop_front();
-    if(lst.size()<5) return;
+    if(lst.size() < 6)
+    {
+      qWarning("Net: Bad CONFIGURED message");
+      return;
+    }
     emit seedChanged(lst[0]);
     emit mapChanged(lst[1]);
     emit themeChanged(lst[2]);
@@ -218,12 +238,22 @@
   }
 
   if(lst[0]=="TEAM_ACCEPTED") {
+    if(lst.size() < 3)
+    {
+      qWarning("Net: Bad TEAM_ACCEPTED message");
+      return;
+    }
     m_networkToLocalteams.insert(lst[2].toUInt(), lst[1]);
     m_pTeamSelWidget->changeTeamStatus(lst[1]);
     return;
   }
 
   if (lst[0] == "CONFIG_PARAM") {
+    if(lst.size() < 3)
+    {
+      qWarning("Net: Bad CONFIG_PARAM message");
+      return;
+    }
   	if (lst[1] == "SEED") {
 	  emit seedChanged(lst[2]);
 	  return;
@@ -267,6 +297,7 @@
 	  emit hhnumChanged(tmptm);
 	  return;
   	}
+    qWarning(QString("Net: Unknown 'CONFIG_PARAM' message: '%1'").arg(msg).toAscii().data());
     return;
   }
 
@@ -274,10 +305,17 @@
   // should be kinda game states, which don't allow "GAMEMSG:" at configure step,
   // "CONNECTED" at round phase, etc.
   if (lst[0] == "GAMEMSG:") {
+    if(lst.size() < 2)
+    {
+      qWarning("Net: Bad LEFT message");
+      return;
+    }
     QByteArray em = QByteArray::fromBase64(lst[1].toAscii());
     emit FromNet(em);
     return;
   }
+
+  qWarning(QString("Net: Unknown message: '%1'").arg(msg).toAscii().data());
 }