From b2443a55c50cffcc30798b2edf6b09b20a3da493 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Mon, 23 Sep 2013 09:04:17 -0400 Subject: [PATCH] Bug 917965 - Don't apply or save invalid updates. r=fabrice --- netwerk/protocol/http/UserAgentUpdates.jsm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/netwerk/protocol/http/UserAgentUpdates.jsm b/netwerk/protocol/http/UserAgentUpdates.jsm index 5c03d1548666..d0a4341cd20c 100644 --- a/netwerk/protocol/http/UserAgentUpdates.jsm +++ b/netwerk/protocol/http/UserAgentUpdates.jsm @@ -95,7 +95,13 @@ this.UserAgentUpdates = { 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(); @@ -170,7 +176,10 @@ this.UserAgentUpdates = { 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(); },