Bug 1349690. Improve dangling-exception logging in AutoJSAPI::InitInternal to deal better with exceptions from a different origin. r=bholley
☠☠ backed out by 85658d613c77 ☠ ☠
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 23 Mar 2017 03:06:25 -0400
changeset 348940 3ccb231829a94c8d5aff22222ecfe0ef1f1d50a7
parent 348939 8ba41a1bd062a484ed24a5a25758c13eb57b8429
child 348941 6235799ad4fd1e408a6c348c41f04d9ff7582e3d
push id88364
push userbzbarsky@mozilla.com
push dateThu, 23 Mar 2017 07:06:40 +0000
treeherdermozilla-inbound@3ccb231829a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1349690
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1349690. Improve dangling-exception logging in AutoJSAPI::InitInternal to deal better with exceptions from a different origin. r=bholley MozReview-Commit-ID: IpvRcBC2d6k
dom/base/ScriptSettings.cpp
--- a/dom/base/ScriptSettings.cpp
+++ b/dom/base/ScriptSettings.cpp
@@ -371,16 +371,23 @@ AutoJSAPI::InitInternal(nsIGlobalObject*
   if (haveException) {
     JS::Rooted<JS::Value> exn(aCx);
     JS_GetPendingException(aCx, &exn);
 
     JS_ClearPendingException(aCx);
     if (exn.isObject()) {
       JS::Rooted<JSObject*> exnObj(aCx, &exn.toObject());
 
+      // Make sure we can actually read things from it.  This UncheckedUwrap is
+      // safe because we're only getting data for a debug printf.  In
+      // particular, we do not expose this data to anyone, which is very
+      // important; otherwise it could be a cross-origin information leak.
+      exnObj = js::UncheckedUwrap(exnObj);
+      JSAutoCompartment ac(aCx, exnObj);
+
       nsAutoJSString stack, filename, name, message;
       int32_t line;
 
       JS::Rooted<JS::Value> tmp(aCx);
       if (!JS_GetProperty(aCx, exnObj, "filename", &tmp)) {
         JS_ClearPendingException(aCx);
       }
       if (tmp.isUndefined()) {