Bug 1238142 - Harden Telemetry addon data collection. r=gfritzsche

This commit is contained in:
Alessio Placitelli 2016-01-13 06:02:00 +01:00
parent d503e8158c
commit 53d98d8518

View File

@ -264,7 +264,7 @@ function getGfxField(aPropertyName, aDefault) {
* @return {String} The substring or null if the input string is null. * @return {String} The substring or null if the input string is null.
*/ */
function limitStringToLength(aString, aMaxLength) { function limitStringToLength(aString, aMaxLength) {
if (aString === null || aString === undefined) { if (typeof(aString) !== "string") {
return null; return null;
} }
return aString.substring(0, aMaxLength); return aString.substring(0, aMaxLength);
@ -515,28 +515,36 @@ EnvironmentAddonBuilder.prototype = {
continue; continue;
} }
// Make sure to have valid dates. // Weird addon data in the wild can lead to exceptions while collecting
let installDate = new Date(Math.max(0, addon.installDate)); // the data.
let updateDate = new Date(Math.max(0, addon.updateDate)); try {
// Make sure to have valid dates.
let installDate = new Date(Math.max(0, addon.installDate));
let updateDate = new Date(Math.max(0, addon.updateDate));
activeAddons[addon.id] = { activeAddons[addon.id] = {
blocklisted: (addon.blocklistState !== Ci.nsIBlocklistService.STATE_NOT_BLOCKED), blocklisted: (addon.blocklistState !== Ci.nsIBlocklistService.STATE_NOT_BLOCKED),
description: limitStringToLength(addon.description, MAX_ADDON_STRING_LENGTH), description: limitStringToLength(addon.description, MAX_ADDON_STRING_LENGTH),
name: limitStringToLength(addon.name, MAX_ADDON_STRING_LENGTH), name: limitStringToLength(addon.name, MAX_ADDON_STRING_LENGTH),
userDisabled: addon.userDisabled, userDisabled: addon.userDisabled,
appDisabled: addon.appDisabled, appDisabled: addon.appDisabled,
version: limitStringToLength(addon.version, MAX_ADDON_STRING_LENGTH), version: limitStringToLength(addon.version, MAX_ADDON_STRING_LENGTH),
scope: addon.scope, scope: addon.scope,
type: addon.type, type: addon.type,
foreignInstall: addon.foreignInstall, foreignInstall: addon.foreignInstall,
hasBinaryComponents: addon.hasBinaryComponents, hasBinaryComponents: addon.hasBinaryComponents,
installDay: Utils.millisecondsToDays(installDate.getTime()), installDay: Utils.millisecondsToDays(installDate.getTime()),
updateDay: Utils.millisecondsToDays(updateDate.getTime()), updateDay: Utils.millisecondsToDays(updateDate.getTime()),
signedState: addon.signedState, signedState: addon.signedState,
}; };
if (addon.signedState !== undefined) if (addon.signedState !== undefined)
activeAddons[addon.id].signedState = addon.signedState; activeAddons[addon.id].signedState = addon.signedState;
} catch (ex) {
this._environment._log.error("_getActiveAddons - An addon was discarded due to an error", ex);
continue;
}
} }
return activeAddons; return activeAddons;
@ -592,19 +600,24 @@ EnvironmentAddonBuilder.prototype = {
continue; continue;
} }
// Make sure to have a valid date. try {
let updateDate = new Date(Math.max(0, tag.lastModifiedTime)); // Make sure to have a valid date.
let updateDate = new Date(Math.max(0, tag.lastModifiedTime));
activePlugins.push({ activePlugins.push({
name: limitStringToLength(tag.name, MAX_ADDON_STRING_LENGTH), name: limitStringToLength(tag.name, MAX_ADDON_STRING_LENGTH),
version: limitStringToLength(tag.version, MAX_ADDON_STRING_LENGTH), version: limitStringToLength(tag.version, MAX_ADDON_STRING_LENGTH),
description: limitStringToLength(tag.description, MAX_ADDON_STRING_LENGTH), description: limitStringToLength(tag.description, MAX_ADDON_STRING_LENGTH),
blocklisted: tag.blocklisted, blocklisted: tag.blocklisted,
disabled: tag.disabled, disabled: tag.disabled,
clicktoplay: tag.clicktoplay, clicktoplay: tag.clicktoplay,
mimeTypes: tag.getMimeTypes({}), mimeTypes: tag.getMimeTypes({}),
updateDay: Utils.millisecondsToDays(updateDate.getTime()), updateDay: Utils.millisecondsToDays(updateDate.getTime()),
}); });
} catch (ex) {
this._environment._log.error("_getActivePlugins - A plugin was discarded due to an error", ex);
continue;
}
} }
return activePlugins; return activePlugins;
@ -628,11 +641,16 @@ EnvironmentAddonBuilder.prototype = {
continue; continue;
} }
activeGMPlugins[plugin.id] = { try {
version: plugin.version, activeGMPlugins[plugin.id] = {
userDisabled: plugin.userDisabled, version: plugin.version,
applyBackgroundUpdates: plugin.applyBackgroundUpdates, userDisabled: plugin.userDisabled,
}; applyBackgroundUpdates: plugin.applyBackgroundUpdates,
};
} catch (ex) {
this._environment._log.error("_getActiveGMPlugins - A GMPlugin was discarded due to an error", ex);
continue;
}
} }
return activeGMPlugins; return activeGMPlugins;