From 9132b1c982ae2ff48dd41462c2248008e3a2d208 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 13 Jan 2026 02:39:43 +0000 Subject: [PATCH] avoid going out bounds on llInsertString. Thx Tampa --- .../Shared/Api/Implementation/LSL_Api.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index e2f2adf73f..4f10b8de6d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3161,19 +3161,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // this is actually wrong. according to SL wiki, this function should not support negative indexes. public LSL_String llInsertString(string dest, int index, string src) { + if(string.IsNullOrEmpty(src)) + return dest; + // Normalize indices (if negative). // After normalization they may still be // negative, but that is now relative to // the start, rather than the end, of the // sequence. + char c; if (index < 0) { - index = dest.Length+index; + index = dest.Length + index; // Negative now means it is less than the lower // bound of the string. - if(index > 0) + if(index >= 0 && index < dest.Length) { c = dest[index]; if (c >= 0xDC00 && c <= 0xDFFF) @@ -3182,11 +3186,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (index < 0) { - return src+dest; + return src + dest; } } - else + else if(index < dest.Length) { c = dest[index]; if (c >= 0xDC00 && c <= 0xDFFF)