Bug 838342 - Delete checksum-invalid saved pings. r=froydnj
authorTaras Glek <tglek@mozilla.com>
Tue, 05 Feb 2013 21:13:43 -0500
changeset 130855 fa591204a58740859c69480a229b7b0b9213846a
parent 130854 e6c3449a8ec625a80148499d6c38cee390648016
child 130856 2716ae058067065178c2ad5e5b1cc0e6ffa545cd
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs838342
milestone21.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 838342 - Delete checksum-invalid saved pings. r=froydnj
toolkit/components/telemetry/TelemetryPing.js
--- a/toolkit/components/telemetry/TelemetryPing.js
+++ b/toolkit/components/telemetry/TelemetryPing.js
@@ -766,46 +766,46 @@ TelemetryPing.prototype = {
       Telemetry.asyncFetchTelemetryData(function () {
       });
       delete this._timer;
     }
     this._timer.initWithCallback(timerCallback.bind(this), TELEMETRY_DELAY,
                                  Ci.nsITimer.TYPE_ONE_SHOT);
   },
 
-  verifyPingChecksum: function verifyPingChecksum(ping) {
+  ensurePingChecksum: function ensurePingChecksum(ping) {
     /* A ping from the current session won't have a checksum.  */
     if (!ping.checksum) {
-      return true;
+      return;
     }
 
     let checksumNow = this.hashString(ping.payload);
-    return ping.checksum == checksumNow;
+    if (ping.checksum != checksumNow) {
+      throw new Error("Invalid ping checksum")
+    }
   },
 
   addToPendingPings: function addToPendingPings(file, stream) {
     let success = false;
 
     try {
       let string = NetUtil.readInputStreamToString(stream, stream.available(), { charset: "UTF-8" });
       stream.close();
       let ping = JSON.parse(string);
       this._pingLoadsCompleted++;
-
-      if (this.verifyPingChecksum(ping)) {
-        this._pendingPings.push(ping);
-      }
-
+      // This will throw if checksum is invalid.
+      this.ensurePingChecksum(ping);
+      this._pendingPings.push(ping);
       if (this._doLoadSaveNotifications &&
           this._pingLoadsCompleted == this._pingsLoaded) {
         Services.obs.notifyObservers(null, "telemetry-test-load-complete", null);
       }
       success = true;
     } catch (e) {
-      // An error reading the file, or an error parsing the contents.
+      // An error reading the file, or an error parsing/checksumming the contents.
       stream.close();           // close is idempotent.
       file.remove(true);
     }
     let success_histogram = Telemetry.getHistogramById("READ_SAVED_PING_SUCCESS");
     success_histogram.add(success);
   },
 
   loadHistograms: function loadHistograms(file, sync) {