[Bug 671520] Port Bug 668646 [Invalid cookie hosts causes sessionstore to stop updating]. r=Neil
authorMisak Khachatryan <misak.bugzilla@gmail.com>
Thu, 14 Jul 2011 16:00:32 +0500
changeset 8287 e42ccacdc80ad5054a1c5d7100c82622c49c8559
parent 8286 8bb302ea0895a775db22722507228571479e5e53
child 8288 45a849aee6165bb8e10b3d46cd0c0b61ceaef9c3
push id107
push userbugzilla@standard8.plus.com
push dateTue, 16 Aug 2011 23:11:19 +0000
treeherdercomm-aurora@cefe50ba1568 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs671520, 668646
[Bug 671520] Port Bug 668646 [Invalid cookie hosts causes sessionstore to stop updating]. r=Neil
suite/common/src/nsSessionStore.js
--- a/suite/common/src/nsSessionStore.js
+++ b/suite/common/src/nsSessionStore.js
@@ -2015,47 +2015,52 @@ SessionStoreService.prototype = {
     var jscookies = {};
     var _this = this;
     // MAX_EXPIRY should be 2^63-1, but JavaScript can't handle that precision
     var MAX_EXPIRY = Math.pow(2, 62);
     aWindows.forEach(function(aWindow) {
       if (!aWindow._hosts)
         return;
       for (var [host, isPinned] in Iterator(aWindow._hosts)) {
-        var list = Services.cookies.getCookiesFromHost(host);
-        while (list.hasMoreElements()) {
-          var cookie = list.getNext().QueryInterface(Components.interfaces.nsICookie2);
-          // aWindow._hosts will only have hosts with the right privacy rules,
-          // so there is no need to do anything special with this call to
-          // _checkPrivacyLevel.
-          if (cookie.isSession && _this._checkPrivacyLevel(cookie.isSecure, isPinned)) {
-            // use the cookie's host, path, and name as keys into a hash,
-            // to make sure we serialize each cookie only once
-
-            // lazily build up a 3-dimensional hash, with
-            // host, path, and name as keys
-            if (!jscookies[cookie.host])
-              jscookies[cookie.host] = {};
-            if (!jscookies[cookie.host][cookie.path])
-              jscookies[cookie.host][cookie.path] = {};
-
-            if (!jscookies[cookie.host][cookie.path][cookie.name]) {
-              var jscookie = { "host": cookie.host, "value": cookie.value };
-              // only add attributes with non-default values (saving a few bits)
-              if (cookie.path) jscookie.path = cookie.path;
-              if (cookie.name) jscookie.name = cookie.name;
-              if (cookie.isSecure) jscookie.secure = true;
-              if (cookie.isHttpOnly) jscookie.httponly = true;
-              if (cookie.expiry < MAX_EXPIRY) jscookie.expiry = cookie.expiry;
-  
-              jscookies[cookie.host][cookie.path][cookie.name] = jscookie;
+        try {
+          var list = Services.cookies.getCookiesFromHost(host);
+          while (list.hasMoreElements()) {
+            var cookie = list.getNext().QueryInterface(Components.interfaces.nsICookie2);
+            // aWindow._hosts will only have hosts with the right privacy rules,
+            // so there is no need to do anything special with this call to
+            // _checkPrivacyLevel.
+            if (cookie.isSession && _this._checkPrivacyLevel(cookie.isSecure, isPinned)) {
+              // use the cookie's host, path, and name as keys into a hash,
+              // to make sure we serialize each cookie only once
+
+              // lazily build up a 3-dimensional hash, with
+              // host, path, and name as keys
+              if (!jscookies[cookie.host])
+                jscookies[cookie.host] = {};
+              if (!jscookies[cookie.host][cookie.path])
+                jscookies[cookie.host][cookie.path] = {};
+
+              if (!jscookies[cookie.host][cookie.path][cookie.name]) {
+                var jscookie = { "host": cookie.host, "value": cookie.value };
+                // only add attributes with non-default values (saving a few bits)
+                if (cookie.path) jscookie.path = cookie.path;
+                if (cookie.name) jscookie.name = cookie.name;
+                if (cookie.isSecure) jscookie.secure = true;
+                if (cookie.isHttpOnly) jscookie.httponly = true;
+                if (cookie.expiry < MAX_EXPIRY) jscookie.expiry = cookie.expiry;
+
+                jscookies[cookie.host][cookie.path][cookie.name] = jscookie;
+              }
+              aWindow.cookies.push(jscookies[cookie.host][cookie.path][cookie.name]);
             }
-            aWindow.cookies.push(jscookies[cookie.host][cookie.path][cookie.name]);
           }
         }
+        catch (ex) {
+          debug("getCookiesFromHost failed. Host: " + host);
+        }
       }
     });
 
     // don't include empty cookie sections
     for (i = 0; i < aWindows.length; i++)
       if (aWindows[i].cookies.length == 0)
         delete aWindows[i].cookies;
   },