From e7f1f4551092cdc4d23ff89d37e77a42096cd48e Mon Sep 17 00:00:00 2001
From: Josh Bell <josh@lindenlab.com>
Date: Wed, 13 Feb 2008 18:07:18 +0000
Subject: [PATCH] svn merge -r 79455:79892
 svn+ssh://svn.lindenlab.com/svn/linden/branches/Branch_1-19-0-Server -->
 release

* DEV-10498 The agentN-ds host name was constructed incorrectly and caused services_base_url to be incorrect
* Fixed a potential crash bug caused by LSL library functions returning null pointers instead of empty strings.
---
 indra/lscript/lscript_byteconvert.h             |  2 +-
 indra/lscript/lscript_library/lscript_alloc.cpp | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/indra/lscript/lscript_byteconvert.h b/indra/lscript/lscript_byteconvert.h
index 6d0e2d08f3f..923b2b402db 100644
--- a/indra/lscript/lscript_byteconvert.h
+++ b/indra/lscript/lscript_byteconvert.h
@@ -168,7 +168,7 @@ inline void bytestream2char(char *buffer, const U8 *stream, S32 &offset)
 		;
 }
 
-inline void char2bytestream(U8 *stream, S32 &offset, char *buffer)
+inline void char2bytestream(U8 *stream, S32 &offset, const char *buffer)
 {
 	while ((*(stream + offset++) = *buffer++))
 		;
diff --git a/indra/lscript/lscript_library/lscript_alloc.cpp b/indra/lscript/lscript_library/lscript_alloc.cpp
index a2f83e7cd95..dac83eb3a8e 100644
--- a/indra/lscript/lscript_library/lscript_alloc.cpp
+++ b/indra/lscript/lscript_library/lscript_alloc.cpp
@@ -131,10 +131,12 @@ S32 lsa_heap_add_data(U8 *buffer, LLScriptLibData *data, S32 heapsize, BOOL b_de
 		size = 4;
 		break;
 	case LST_KEY:
-		size = (S32)strlen(data->mKey) + 1;			/*Flawfinder: ignore*/
+	        // NOTE: babbage: defensive as some library calls set data to NULL
+	        size = data->mKey ? (S32)strlen(data->mKey) + 1 : 1; /*Flawfinder: ignore*/
 		break;
 	case LST_STRING:
-		size = (S32)strlen(data->mString) + 1;		/*Flawfinder: ignore*/ 
+                // NOTE: babbage: defensive as some library calls set data to NULL
+            	size = data->mString ? (S32)strlen(data->mString) + 1 : 1; /*Flawfinder: ignore*/
 		break;
 	case LST_LIST:
 		//	list data		4 bytes of number of entries followed by number of pointer
@@ -294,10 +296,10 @@ void lsa_insert_data(U8 *buffer, S32 &offset, LLScriptLibData *data, LLScriptAll
 			float2bytestream(buffer, offset, data->mFP);
 			break;
 		case LST_KEY:
-			char2bytestream(buffer, offset, data->mKey);
+		        char2bytestream(buffer, offset, data->mKey ? data->mKey : "");
 			break;
 		case LST_STRING:
-			char2bytestream(buffer, offset, data->mString);
+		        char2bytestream(buffer, offset, data->mString ? data->mString : "");
 			break;
 		case LST_VECTOR:
 			vector2bytestream(buffer, offset, data->mVec);
-- 
GitLab