Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
[Merge chakra-core/ChakraCore@a9c6c2dc41] [1.6>1.7] [MERGE #3416 @cur…
Browse files Browse the repository at this point in the history
…tisman] Fix Issue #3261: Need to detect invalid null character at the end of the source string

Merge pull request #3416 from curtisman:fix3261
  • Loading branch information
chakrabot authored and kfarnung committed Aug 10, 2017
1 parent dfc1581 commit 68380ca
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion deps/chakrashim/core/bin/ch/WScriptJsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ bool WScriptJsrt::Initialize()
;

JsValueRef $262ScriptRef;
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateStringUtf16((uint16_t*)$262, _countof($262), &$262ScriptRef));
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateStringUtf16((uint16_t*)$262, _countof($262) - 1, &$262ScriptRef));

JsValueRef fname;
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateString("$262", strlen("$262"), &fname));
Expand Down
15 changes: 9 additions & 6 deletions deps/chakrashim/core/lib/Parser/Scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ tokens Scanner<EncodingPolicy>::ScanStringConstant(OLECHAR delim, EncodedCharPtr
goto LMainDefault;

case kchNUL:
if (p >= last)
if (p > last)
{
m_currentCharacter = p - 1;
Error(ERRnoStrEnd);
Expand Down Expand Up @@ -1723,14 +1723,14 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
case '\0':
// Put back the null in case we get called again.
p--;
LEof:
token = tkEOF;

if (p + 1 < last)
if (p < last)
{
// A \0 prior to the end of the text is an invalid character.
Error(ERRillegalChar);
}
LEof:
Assert(p >= last);
token = tkEOF;
break;

case 0x0009:
Expand Down Expand Up @@ -2031,7 +2031,10 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds)
m_parser->ReduceDeferredScriptLength((ULONG)(p - m_pchMinTok));
break;
case kchNUL:
if (p >= last)
// Because we used ReadFirst, we have advanced p. The character that we are looking at is actually is p - 1.
// If p == last, we are looking at p - 1, it is still within the source buffer, and we need to consider it part of the comment
// Only if p > last that we have pass the source buffer and consider it a line break
if (p > last)
{
p--;
goto LCommentLineBreak;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
SyntaxError: Invalid character
1
1
SyntaxError: Invalid character
15 changes: 8 additions & 7 deletions deps/chakrashim/core/test/GlobalFunctions/evalNullsNewlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ function write(str) {
}
}

write("--- 1 ---"); // CHROME IE8
try { write(eval('1+//\0\n1')); } catch (e) { write(e); } // 2 !
try { write(eval('"a\0b"').length); } catch (e) { write(e); } // 3 !
try { write(eval('\'a\0b\'').length); } catch (e) { write(e); } // 3 !
try { write(eval('\0 = 1')); } catch (e) { write(e); } // ! undefined
try { write(eval('/*\0*/1')); } catch (e) { write(e); } // 1 !
try { write(eval('1//\0')); } catch (e) { write(e); } // 1 1
write("--- 1 ---");
try { write(eval('1+//\0\n1')); } catch (e) { write(e); } // 2
try { write(eval('"a\0b"').length); } catch (e) { write(e); } // 3
try { write(eval('\'a\0b\'').length); } catch (e) { write(e); } // 3
try { write(eval('\0 = 1')); } catch (e) { write(e); } // !
try { write(eval('/*\0*/1')); } catch (e) { write(e); } // 1
try { write(eval('1//\0')); } catch (e) { write(e); } // 1
try { write(eval('1\0')); } catch (e) { write(e); } // !

0 comments on commit 68380ca

Please sign in to comment.