From f3778f7fcc6b691ddf53743f17d0c27c4232ce94 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Wed, 12 Jan 2022 23:21:52 +0200
Subject: [PATCH] SL-16637 Better validation of data in
 LLEstablishAgentCommunication

Do not set capability when disconnected, it creates new coroutines that will do nothing and region might be invalid resulting in a crash. Do not initilize LLWorld.
---
 indra/newview/llworld.cpp | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/indra/newview/llworld.cpp b/indra/newview/llworld.cpp
index fb3fc55a94c..81511ac5559 100644
--- a/indra/newview/llworld.cpp
+++ b/indra/newview/llworld.cpp
@@ -1195,6 +1195,16 @@ class LLEstablishAgentCommunication : public LLHTTPNode
 	virtual void post(ResponsePtr response, const LLSD& context, const LLSD& input) const
 	{
         if (LLApp::isExiting())
+        {
+            return;
+        }
+
+        if (gDisconnected)
+        {
+            return;
+        }
+
+        if (!LLWorld::instanceExists())
         {
             return;
         }
@@ -1207,8 +1217,13 @@ class LLEstablishAgentCommunication : public LLHTTPNode
             return;
 		}
 
-		LLHost sim(input["body"]["sim-ip-and-port"].asString());
-	
+        LLHost sim(input["body"]["sim-ip-and-port"].asString());
+        if (sim.isInvalid())
+        {
+            LL_WARNS() << "Got EstablishAgentCommunication with invalid host" << LL_ENDL;
+            return;
+        }
+
 		LLViewerRegion* regionp = LLWorld::getInstance()->getRegion(sim);
 		if (!regionp)
 		{
@@ -1217,7 +1232,7 @@ class LLEstablishAgentCommunication : public LLHTTPNode
 			return;
 		}
 		LL_DEBUGS("CrossingCaps") << "Calling setSeedCapability from LLEstablishAgentCommunication::post. Seed cap == "
-				<< input["body"]["seed-capability"] << LL_ENDL;
+				<< input["body"]["seed-capability"] << " for region " << regionp->getRegionID() << LL_ENDL;
 		regionp->setSeedCapability(input["body"]["seed-capability"]);
 	}
 };
-- 
GitLab