Bug 917965 - Don't apply or save invalid updates. r=fabrice, a=koi+
authorJim Chen <nchen@mozilla.com>
Mon, 23 Sep 2013 09:04:17 -0400
changeset 160409 a59d0e8196a05f54c876ed3def373108a53e5d57
parent 160408 034e248039f617b0c5935550196e80b17810069d
child 160410 4cb0a48b757422c7ebdbebe208b52dd0e0cfb9d0
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice, koi
bugs917965
milestone26.0a2
Bug 917965 - Don't apply or save invalid updates. r=fabrice, a=koi+
netwerk/protocol/http/UserAgentUpdates.jsm
--- a/netwerk/protocol/http/UserAgentUpdates.jsm
+++ b/netwerk/protocol/http/UserAgentUpdates.jsm
@@ -90,17 +90,23 @@ this.UserAgentUpdates = {
       return;
     }
     // try loading from profile dir, then from app dir
     let dirs = [KEY_PREFDIR, KEY_APPDIR];
     dirs.reduce((prevLoad, dir) => {
       let file = FileUtils.getFile(dir, [FILE_UPDATES], true).path;
       // tryNext returns promise to read file under dir and parse it
       let tryNext = () => OS.File.read(file).then(
-        (bytes) => JSON.parse(gDecoder.decode(bytes))
+        (bytes) => {
+          let update = JSON.parse(gDecoder.decode(bytes));
+          if (!update) {
+            throw new Error("invalid update");
+          }
+          return update;
+        }
       );
       // try to load next one if the previous load failed
       return prevLoad ? prevLoad.then(null, tryNext) : tryNext();
     }, null).then(
       // apply update if loading was successful
       (update) => this._applyUpdate(update)
     );
     this._scheduleUpdate();
@@ -165,17 +171,20 @@ this.UserAgentUpdates = {
     let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
                     .createInstance(Ci.nsIXMLHttpRequest);
     request.mozBackgroundRequest = true;
     request.timeout = this._getPref(PREF_UPDATES_TIMEOUT, 60000);
     request.open("GET", url, true);
     request.overrideMimeType("application/json");
     request.responseType = "json";
 
-    request.addEventListener("load", function() success(request.response));
+    request.addEventListener("load", function() {
+      let response = request.response;
+      response ? success(response) : error();
+    });
     request.addEventListener("error", error);
     request.send();
   },
 
   _update: function() {
     let url = this._getUpdateURL();
     url && this._fetchUpdate(url,
       (function(response) { // success