Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 7b57891

Browse files
committed
[[ Bug 22586 ]] Fix buffer overrun in native split
This patch fixes a buffer overrun in the native split codepath where adding the key length to the ptr used to extract the element could result in a start pointer higher than the end ptr. Subtracting from the end ptr to find the length resulted in a very high length due to unsignedness thus causing invalid access.
1 parent df34a44 commit 7b57891

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

docs/notes/bugfix-22586.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix crash in `split` command with multi-char delimiter

libfoundation/src/foundation-string.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5263,9 +5263,9 @@ bool MCStringSplitNative(MCStringRef self, MCStringRef p_elem_del, MCStringRef p
52635263
if (!MCNameCreateWithNativeChars(t_sptr, t_key_end - t_sptr, &t_name))
52645264
return false;
52655265

5266-
if (t_key_end != t_element_end)
5266+
if (t_key_end <= t_element_end - p_key_del -> char_count)
52675267
t_key_end += p_key_del -> char_count;
5268-
5268+
52695269
MCAutoStringRef t_string;
52705270
if (!MCStringCreateWithNativeChars(t_key_end, t_element_end - t_key_end, &t_string))
52715271
return false;

tests/lcs/core/array/split.livecodescript

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,14 @@ on TestSplitAsSet
239239
split tResult with empty as set
240240
TestAssert "split set (native, empty)", tResult is tExpected
241241
end TestSplitAsSet
242+
243+
on TestBug22586
244+
local tVar
245+
put "foo" into tVar
246+
split tVar by return and ": "
247+
TestAssert "native split by unfound multi-char delimiter does not crash", true
248+
249+
put "foo" & numToCodePoint(0x2192) into tVar
250+
split tVar by return and ": "
251+
TestAssert "unicode split by unfound multi-char delimiter does not crash", true
252+
end TestBug22586

0 commit comments

Comments
 (0)