<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[196745] trunk/Source</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/196745">196745</a></dd>
<dt>Author</dt> <dd>mark.lam@apple.com</dd>
<dt>Date</dt> <dd>2016-02-17 22:28:26 -0800 (Wed, 17 Feb 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Callers of JSString::value() should check for exceptions thereafter.
https://bugs.webkit.org/show_bug.cgi?id=154346
Reviewed by Geoffrey Garen.
Source/JavaScriptCore:
JSString::value() can throw an exception if the JS string is a rope and value()
needs to resolve the rope but encounters an OutOfMemory error. If value() is not
able to resolve the rope, it will return a null string (in addition to throwing
the exception). If a caller does not check for exceptions after calling
JSString::value(), they may eventually use the returned null string and crash the
VM.
The fix is to add all the necessary exception checks, and do the appropriate
handling if needed.
* jsc.cpp:
(functionRun):
(functionLoad):
(functionReadFile):
(functionCheckSyntax):
(functionLoadWebAssembly):
(functionLoadModule):
(functionCheckModuleSyntax):
* runtime/DateConstructor.cpp:
(JSC::dateParse):
(JSC::dateNow):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalFuncEval):
* tools/JSDollarVMPrototype.cpp:
(JSC::functionPrint):
Source/WebCore:
No new tests. The crash that results from this issue is dependent on a race
condition where an OutOfMemory error occurs precisely at the point where the
JSString::value() function is called on a rope JSString.
* bindings/js/JSHTMLAllCollectionCustom.cpp:
(WebCore::callHTMLAllCollection):
* bindings/js/JSStorageCustom.cpp:
(WebCore::JSStorage::putDelegate):
- Added a comment at the site of the exception check to clarify the meaning of
the return value.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorejsccpp">trunk/Source/JavaScriptCore/jsc.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeDateConstructorcpp">trunk/Source/JavaScriptCore/runtime/DateConstructor.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjectFunctionscpp">trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoretoolsJSDollarVMPrototypecpp">trunk/Source/JavaScriptCore/tools/JSDollarVMPrototype.cpp</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSHTMLAllCollectionCustomcpp">trunk/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSStorageCustomcpp">trunk/Source/WebCore/bindings/js/JSStorageCustom.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (196744 => 196745)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-02-18 06:13:15 UTC (rev 196744)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-02-18 06:28:26 UTC (rev 196745)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2016-02-17 Mark Lam <mark.lam@apple.com>
+
+ Callers of JSString::value() should check for exceptions thereafter.
+ https://bugs.webkit.org/show_bug.cgi?id=154346
+
+ Reviewed by Geoffrey Garen.
+
+ JSString::value() can throw an exception if the JS string is a rope and value()
+ needs to resolve the rope but encounters an OutOfMemory error. If value() is not
+ able to resolve the rope, it will return a null string (in addition to throwing
+ the exception). If a caller does not check for exceptions after calling
+ JSString::value(), they may eventually use the returned null string and crash the
+ VM.
+
+ The fix is to add all the necessary exception checks, and do the appropriate
+ handling if needed.
+
+ * jsc.cpp:
+ (functionRun):
+ (functionLoad):
+ (functionReadFile):
+ (functionCheckSyntax):
+ (functionLoadWebAssembly):
+ (functionLoadModule):
+ (functionCheckModuleSyntax):
+ * runtime/DateConstructor.cpp:
+ (JSC::dateParse):
+ (JSC::dateNow):
+ * runtime/JSGlobalObjectFunctions.cpp:
+ (JSC::globalFuncEval):
+ * tools/JSDollarVMPrototype.cpp:
+ (JSC::functionPrint):
+
</ins><span class="cx"> 2016-02-17 Benjamin Poulain <bpoulain@apple.com>
</span><span class="cx">
</span><span class="cx"> [JSC] ARM64: Support the immediate format used for bit operations in Air
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorejsccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/jsc.cpp (196744 => 196745)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/jsc.cpp        2016-02-18 06:13:15 UTC (rev 196744)
+++ trunk/Source/JavaScriptCore/jsc.cpp        2016-02-18 06:28:26 UTC (rev 196745)
</span><span class="lines">@@ -1243,6 +1243,8 @@
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL functionRun(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> String fileName = exec->argument(0).toString(exec)->value(exec);
</span><ins>+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
</ins><span class="cx"> Vector<char> script;
</span><span class="cx"> if (!fetchScriptFromLocalFileSystem(fileName, script))
</span><span class="cx"> return JSValue::encode(exec->vm().throwException(exec, createError(exec, ASCIILiteral("Could not open file."))));
</span><span class="lines">@@ -1272,6 +1274,8 @@
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL functionLoad(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> String fileName = exec->argument(0).toString(exec)->value(exec);
</span><ins>+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
</ins><span class="cx"> Vector<char> script;
</span><span class="cx"> if (!fetchScriptFromLocalFileSystem(fileName, script))
</span><span class="cx"> return JSValue::encode(exec->vm().throwException(exec, createError(exec, ASCIILiteral("Could not open file."))));
</span><span class="lines">@@ -1288,6 +1292,8 @@
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL functionReadFile(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> String fileName = exec->argument(0).toString(exec)->value(exec);
</span><ins>+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
</ins><span class="cx"> Vector<char> script;
</span><span class="cx"> if (!fillBufferWithContentsOfFile(fileName, script))
</span><span class="cx"> return JSValue::encode(exec->vm().throwException(exec, createError(exec, ASCIILiteral("Could not open file."))));
</span><span class="lines">@@ -1298,6 +1304,8 @@
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL functionCheckSyntax(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> String fileName = exec->argument(0).toString(exec)->value(exec);
</span><ins>+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
</ins><span class="cx"> Vector<char> script;
</span><span class="cx"> if (!fetchScriptFromLocalFileSystem(fileName, script))
</span><span class="cx"> return JSValue::encode(exec->vm().throwException(exec, createError(exec, ASCIILiteral("Could not open file."))));
</span><span class="lines">@@ -1565,6 +1573,8 @@
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL functionLoadWebAssembly(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> String fileName = exec->argument(0).toString(exec)->value(exec);
</span><ins>+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
</ins><span class="cx"> Vector<char> buffer;
</span><span class="cx"> if (!fillBufferWithContentsOfFile(fileName, buffer))
</span><span class="cx"> return JSValue::encode(exec->vm().throwException(exec, createError(exec, ASCIILiteral("Could not open file."))));
</span><span class="lines">@@ -1584,6 +1594,8 @@
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL functionLoadModule(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> String fileName = exec->argument(0).toString(exec)->value(exec);
</span><ins>+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
</ins><span class="cx"> Vector<char> script;
</span><span class="cx"> if (!fetchScriptFromLocalFileSystem(fileName, script))
</span><span class="cx"> return JSValue::encode(exec->vm().throwException(exec, createError(exec, ASCIILiteral("Could not open file."))));
</span><span class="lines">@@ -1608,6 +1620,8 @@
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL functionCheckModuleSyntax(ExecState* exec)
</span><span class="cx"> {
</span><span class="cx"> String source = exec->argument(0).toString(exec)->value(exec);
</span><ins>+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
</ins><span class="cx">
</span><span class="cx"> StopWatch stopWatch;
</span><span class="cx"> stopWatch.start();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeDateConstructorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/DateConstructor.cpp (196744 => 196745)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/DateConstructor.cpp        2016-02-18 06:13:15 UTC (rev 196744)
+++ trunk/Source/JavaScriptCore/runtime/DateConstructor.cpp        2016-02-18 06:28:26 UTC (rev 196745)
</span><span class="lines">@@ -205,7 +205,10 @@
</span><span class="cx">
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL dateParse(ExecState* exec)
</span><span class="cx"> {
</span><del>- return JSValue::encode(jsNumber(parseDate(exec->vm(), exec->argument(0).toString(exec)->value(exec))));
</del><ins>+ String dateStr = exec->argument(0).toString(exec)->value(exec);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+ return JSValue::encode(jsNumber(parseDate(exec->vm(), dateStr)));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> EncodedJSValue JSC_HOST_CALL dateNow(ExecState* exec)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjectFunctionscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp (196744 => 196745)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp        2016-02-18 06:13:15 UTC (rev 196744)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp        2016-02-18 06:28:26 UTC (rev 196745)
</span><span class="lines">@@ -574,6 +574,8 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> String s = x.toString(exec)->value(exec);
</span><ins>+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
</ins><span class="cx">
</span><span class="cx"> if (s.is8Bit()) {
</span><span class="cx"> LiteralParser<LChar> preparser(exec, s.characters8(), s.length(), NonStrictJSON);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoretoolsJSDollarVMPrototypecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/tools/JSDollarVMPrototype.cpp (196744 => 196745)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/tools/JSDollarVMPrototype.cpp        2016-02-18 06:13:15 UTC (rev 196744)
+++ trunk/Source/JavaScriptCore/tools/JSDollarVMPrototype.cpp        2016-02-18 06:28:26 UTC (rev 196745)
</span><span class="lines">@@ -303,7 +303,10 @@
</span><span class="cx"> for (unsigned i = 0; i < exec->argumentCount(); ++i) {
</span><span class="cx"> if (i)
</span><span class="cx"> dataLog(" ");
</span><del>- dataLog(exec->uncheckedArgument(i).toString(exec)->value(exec));
</del><ins>+ String argStr = exec->uncheckedArgument(i).toString(exec)->value(exec);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
+ dataLog(argStr);
</ins><span class="cx"> }
</span><span class="cx"> return JSValue::encode(jsUndefined());
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (196744 => 196745)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-02-18 06:13:15 UTC (rev 196744)
+++ trunk/Source/WebCore/ChangeLog        2016-02-18 06:28:26 UTC (rev 196745)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-02-17 Mark Lam <mark.lam@apple.com>
+
+ Callers of JSString::value() should check for exceptions thereafter.
+ https://bugs.webkit.org/show_bug.cgi?id=154346
+
+ Reviewed by Geoffrey Garen.
+
+ No new tests. The crash that results from this issue is dependent on a race
+ condition where an OutOfMemory error occurs precisely at the point where the
+ JSString::value() function is called on a rope JSString.
+
+ * bindings/js/JSHTMLAllCollectionCustom.cpp:
+ (WebCore::callHTMLAllCollection):
+ * bindings/js/JSStorageCustom.cpp:
+ (WebCore::JSStorage::putDelegate):
+ - Added a comment at the site of the exception check to clarify the meaning of
+ the return value.
+
</ins><span class="cx"> 2016-02-17 David Kilzer <ddkilzer@apple.com>
</span><span class="cx">
</span><span class="cx"> [Cocoa] Always check the return value of dlopen() and dlsym() in Release builds
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSHTMLAllCollectionCustomcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp (196744 => 196745)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp        2016-02-18 06:13:15 UTC (rev 196744)
+++ trunk/Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp        2016-02-18 06:28:26 UTC (rev 196745)
</span><span class="lines">@@ -65,6 +65,8 @@
</span><span class="cx"> if (exec->argumentCount() == 1) {
</span><span class="cx"> // Support for document.all(<index>) etc.
</span><span class="cx"> String string = exec->argument(0).toString(exec)->value(exec);
</span><ins>+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
</ins><span class="cx"> if (Optional<uint32_t> index = parseIndex(*string.impl()))
</span><span class="cx"> return JSValue::encode(toJS(exec, jsCollection->globalObject(), collection.item(index.value())));
</span><span class="cx">
</span><span class="lines">@@ -74,6 +76,8 @@
</span><span class="cx">
</span><span class="cx"> // The second arg, if set, is the index of the item we want
</span><span class="cx"> String string = exec->argument(0).toString(exec)->value(exec);
</span><ins>+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
</ins><span class="cx"> if (Optional<uint32_t> index = parseIndex(*exec->argument(1).toWTFString(exec).impl())) {
</span><span class="cx"> if (auto* item = collection.namedItemWithIndex(string, index.value()))
</span><span class="cx"> return JSValue::encode(toJS(exec, jsCollection->globalObject(), item));
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSStorageCustomcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSStorageCustom.cpp (196744 => 196745)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSStorageCustom.cpp        2016-02-18 06:13:15 UTC (rev 196744)
+++ trunk/Source/WebCore/bindings/js/JSStorageCustom.cpp        2016-02-18 06:28:26 UTC (rev 196745)
</span><span class="lines">@@ -114,8 +114,13 @@
</span><span class="cx"> return false;
</span><span class="cx">
</span><span class="cx"> String stringValue = value.toString(exec)->value(exec);
</span><del>- if (exec->hadException())
</del><ins>+ if (exec->hadException()) {
+ // The return value indicates whether putDelegate() should handle the put operation (which
+ // if true, tells the caller not to execute the generic put). It does not indicate whether
+ // putDelegate() did successfully complete the operation or not (which it didn't in this
+ // case due to the exception).
</ins><span class="cx"> return true;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> ExceptionCode ec = 0;
</span><span class="cx"> wrapped().setItem(propertyNameToString(propertyName), stringValue, ec);
</span></span></pre>
</div>
</div>
</body>
</html>