Skip to content

Commit 1618253

Browse files
authored
Avoid out of bounds access in String::fromCharCode (#1254)
If c is negative (this can happen if char is signed), then accessing sConstStrings[c] is an out of bounds memory access. This results in a string being created from garbage memory, which can lead to seg faults later on. Taking the other branch is safer in this case.
1 parent 45246fd commit 1618253

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/String.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ Dynamic String::charCodeAt(int inPos) const
13801380

13811381
String String::fromCharCode( int c )
13821382
{
1383-
if (c<=255)
1383+
if (0<=c && c<=255)
13841384
{
13851385
return sConstStrings[c];
13861386
}

0 commit comments

Comments
 (0)