Skip to content

Commit 98a9036

Browse files
boingoingkfarnung
authored andcommitted
deps: update ChakraCore to chakra-core/ChakraCore@1aee42c0ef
[MERGE #4783 @boingoing] Fix a possible null dereference in PopulateMetadataFromException Merge pull request #4783 from boingoing:FixPopulateMetadataFromExceptionNull If the code throwing the exception is dynamic (eval or otherwise doesn't have a url) the url of the `functionBody` can be null. In that case, we would pass null to JavascriptString::NewCopySz which dereferences it and crashes. Fix is to use GetSourceName instead which handles this case providing the string 'eval code' instead of nullptr. Reviewed-By: chakrabot <chakrabot@users.noreply.github.com>
1 parent 9df1c23 commit 98a9036

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

deps/chakrashim/core/bin/NativeTests/JsRTApiTest.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,48 @@ namespace JsRTApiTest
10911091
REQUIRE(JsGetProperty(exceptionMetadata, property, &metadataValue) == JsNoError);
10921092
REQUIRE(JsGetValueType(metadataValue, &type) == JsNoError);
10931093
CHECK(type == JsString);
1094+
1095+
// Following requires eval to be enabled - no point in testing it if we've disabled eval
1096+
if (!(attributes & JsRuntimeAttributeDisableEval))
1097+
{
1098+
REQUIRE(JsRunScript(_u("eval('var a = b');"), JS_SOURCE_CONTEXT_NONE, _u(""), nullptr) == JsErrorScriptException);
1099+
REQUIRE(JsHasException(&value) == JsNoError);
1100+
CHECK(value == true);
1101+
1102+
REQUIRE(JsGetAndClearExceptionWithMetadata(&exceptionMetadata) == JsNoError);
1103+
REQUIRE(JsHasException(&value) == JsNoError);
1104+
CHECK(value == false);
1105+
1106+
REQUIRE(JsGetPropertyIdFromName(_u("exception"), &property) == JsNoError);
1107+
REQUIRE(JsGetProperty(exceptionMetadata, property, &metadataValue) == JsNoError);
1108+
REQUIRE(JsGetValueType(metadataValue, &type) == JsNoError);
1109+
CHECK(type == JsError);
1110+
1111+
REQUIRE(JsGetPropertyIdFromName(_u("line"), &property) == JsNoError);
1112+
REQUIRE(JsGetProperty(exceptionMetadata, property, &metadataValue) == JsNoError);
1113+
REQUIRE(JsGetValueType(metadataValue, &type) == JsNoError);
1114+
CHECK(type == JsNumber);
1115+
1116+
REQUIRE(JsGetPropertyIdFromName(_u("column"), &property) == JsNoError);
1117+
REQUIRE(JsGetProperty(exceptionMetadata, property, &metadataValue) == JsNoError);
1118+
REQUIRE(JsGetValueType(metadataValue, &type) == JsNoError);
1119+
CHECK(type == JsNumber);
1120+
1121+
REQUIRE(JsGetPropertyIdFromName(_u("length"), &property) == JsNoError);
1122+
REQUIRE(JsGetProperty(exceptionMetadata, property, &metadataValue) == JsNoError);
1123+
REQUIRE(JsGetValueType(metadataValue, &type) == JsNoError);
1124+
CHECK(type == JsNumber);
1125+
1126+
REQUIRE(JsGetPropertyIdFromName(_u("url"), &property) == JsNoError);
1127+
REQUIRE(JsGetProperty(exceptionMetadata, property, &metadataValue) == JsNoError);
1128+
REQUIRE(JsGetValueType(metadataValue, &type) == JsNoError);
1129+
CHECK(type == JsString);
1130+
1131+
REQUIRE(JsGetPropertyIdFromName(_u("source"), &property) == JsNoError);
1132+
REQUIRE(JsGetProperty(exceptionMetadata, property, &metadataValue) == JsNoError);
1133+
REQUIRE(JsGetValueType(metadataValue, &type) == JsNoError);
1134+
CHECK(type == JsString);
1135+
}
10941136
}
10951137

10961138
TEST_CASE("ApiTest_ExceptionHandlingTest", "[ApiTest]")

deps/chakrashim/core/lib/Runtime/Library/JavascriptExceptionMetadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace Js {
9191
Js::JavascriptNumber::New(0, scriptContext), scriptContext);
9292

9393
Js::JavascriptOperators::OP_SetProperty(metadata, Js::PropertyIds::url,
94-
Js::JavascriptString::NewCopySz(functionBody->GetSourceContextInfo()->url, scriptContext), scriptContext);
94+
Js::JavascriptString::NewCopySz(functionBody->GetSourceName(), scriptContext), scriptContext);
9595

9696
LPCUTF8 functionSource = sourceInfo->GetSource(_u("Jsrt::JsExperimentalGetAndClearExceptionWithMetadata"));
9797

0 commit comments

Comments
 (0)