Skip to content

Commit 739cde3

Browse files
committed
[MERGE #4169 @akroshg] Fix AV on Date.prototype[Symbol.toPrimitive] call
Merge pull request #4169 from akroshg:dateprim The input of this function was concat string which we failed to flatten that. Which made the null deref AV. Fixed that by using the GetString.
2 parents f15a912 + a0fde21 commit 739cde3

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

lib/Runtime/Library/JavascriptDate.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ namespace Js
260260
if (JavascriptString::Is(args[1]))
261261
{
262262
JavascriptString* StringObject = JavascriptString::FromVar(args[1]);
263+
const char16 * str = StringObject->GetString();
263264

264-
if (wcscmp(StringObject->UnsafeGetBuffer(), _u("default")) == 0 || wcscmp(StringObject->UnsafeGetBuffer(), _u("string")) == 0)
265+
if (wcscmp(str, _u("default")) == 0 || wcscmp(str, _u("string")) == 0)
265266
{
266267
// Date objects, are unique among built-in ECMAScript object in that they treat "default" as being equivalent to "string"
267268
// If hint is the string value "string" or the string value "default", then
@@ -270,7 +271,7 @@ namespace Js
270271
}
271272
// Else if hint is the string value "number", then
272273
// Let tryFirst be "number".
273-
else if(wcscmp(StringObject->UnsafeGetBuffer(), _u("number")) == 0)
274+
else if(wcscmp(str, _u("number")) == 0)
274275
{
275276
return JavascriptConversion::OrdinaryToPrimitive(args[0], JavascriptHint::HintNumber/*tryFirst*/, scriptContext);
276277
}

test/Bugs/misc_bugs.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
7+
8+
var tests = [
9+
{
10+
name: "calling Symbol.toPrimitive on Date prototype should not AV",
11+
body: function () {
12+
Date.prototype[Symbol.toPrimitive].call({},'strin' + 'g');
13+
}
14+
}
15+
];
16+
17+
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

test/Bugs/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@
305305
<compile-flags>-args summary -endargs</compile-flags>
306306
</default>
307307
</test>
308+
<test>
309+
<default>
310+
<files>misc_bugs.js</files>
311+
<compile-flags>-args summary -endargs</compile-flags>
312+
</default>
313+
</test>
308314
<test>
309315
<default>
310316
<files>json_bugs.js</files>

0 commit comments

Comments
 (0)