]> git.mxchange.org Git - flightgear.git/commitdiff
Multiplayer packet boundary warnings
authorRichard Harrison <rjh@zaretto.com>
Thu, 12 May 2016 06:15:52 +0000 (08:15 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 22 Sep 2016 21:27:34 +0000 (23:27 +0200)
* Add warning if multiplayer packet boundary reached
* Add warning if string too big for remaining space in packet

ref: https://sourceforge.net/p/flightgear/mailman/message/35059961/

src/MultiPlayer/multiplaymgr.cxx

index 4cb5b6b4b4500cac0874af341799f8655f34be58..de125aa0e2a42b6e53855fb4d22cd387884a4a53 100644 (file)
@@ -812,8 +812,14 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
       it = motionInfo.properties.begin();
       //cout << "OUTPUT PROPERTIES\n";
       xdr_data_t* msgEnd = msgBuf.propsEnd();
-      while (it != motionInfo.properties.end() && ptr + 2 < msgEnd) {
-        
+      while (it != motionInfo.properties.end()) {
+
+        if (ptr + 2 >= msgEnd)
+        {
+            SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer packet truncated prop id: "+std::to_string((*it)->id));
+            break;
+        }
+
         // First element is the ID. Write it out when we know we have room for
         // the whole property.
         xdr_data_t id =  XDR_encode_uint32((*it)->id);
@@ -846,13 +852,20 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
                 // Add the length         
                 ////cout << "String length: " << strlen(lcharptr) << "\n";
                 uint32_t len = strlen(lcharptr);
-                if (len > MAX_TEXT_SIZE)
-                  len = MAX_TEXT_SIZE;
+                if (len >= MAX_TEXT_SIZE)
+                {
+                  len = MAX_TEXT_SIZE - 1;
+                  SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer property truncated at MAX_TEXT_SIZE in string "+std::to_string((*it)->id));
+                }
+
                 // XXX This should not be using 4 bytes per character!
                 // If there's not enough room for this property, drop it
                 // on the floor.
-                if (ptr + 2 + ((len + 3) & ~3) > msgEnd)
+                if (ptr + 2 + ((len + 3) & ~3) >= msgEnd)
+                {
+                    SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer property not sent (no room) string "+std::to_string((*it)->id));
                     goto escape;
+                }
                 //cout << "String length unint32: " << len << "\n";
                 *ptr++ = id;
                 *ptr++ = XDR_encode_uint32(len);
@@ -863,21 +876,30 @@ FGMultiplayMgr::SendMyPosition(const FGExternalMotionData& motionInfo)
                   int lcount = 0;
                   while ((*lcharptr != '\0') && (lcount < MAX_TEXT_SIZE)) 
                   {
+                    if (ptr + 2 >= msgEnd)
+                    {
+                      SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer packet truncated in string "+std::to_string((*it)->id)+" lcount "+std::to_string(lcount));
+                      break;
+                    }
                     *ptr++ = XDR_encode_int8(*lcharptr);
                     lcharptr++;
                     lcount++;          
                   }
-    
                   //cout << "Prop:" << (*it)->id << " " << (*it)->type << " " << len << " " << (*it)->string_value;
     
                   // Now pad if required
                   while ((lcount % 4) != 0)
                   {
+                    if (ptr + 2 >= msgEnd)
+                    {
+                      SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer packet truncated in string "+std::to_string((*it)->id)+" lcount "+std::to_string(lcount));
+                      break;
+                    }
                     *ptr++ = XDR_encode_int8(0);
                     lcount++;          
                     //cout << "0";
                   }
-                  
+
                   //cout << "\n";
                 }
               }