Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Unified Diff: chrome/browser/extensions/extension_metrics_module.cc

Issue 9113002: Prevent calling internal metrics code with invalid values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« base/metrics/histogram.h ('K') | « base/metrics/histogram.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_metrics_module.cc
diff --git a/chrome/browser/extensions/extension_metrics_module.cc b/chrome/browser/extensions/extension_metrics_module.cc
index 48e5d0821093446bf1b9ea2f863f0f661f549ebf..b68786f8244f8b6a3c50d0c74ff11d001e921258 100644
--- a/chrome/browser/extensions/extension_metrics_module.cc
+++ b/chrome/browser/extensions/extension_metrics_module.cc
@@ -33,6 +33,15 @@ bool MetricsHistogramHelperFunction::RecordValue(const std::string& name,
int max,
size_t buckets,
int sample) {
+ // Make sure toxic values don't get to internal code
jar (doing other things) 2012/01/05 17:35:14 You should also watch out for INT_MAX since you're
rkc 2012/01/06 00:08:01 Done.
+ min = min > 0 ? min : 1;
jar (doing other things) 2012/01/05 17:35:14 nit: (personal style): I find it much more readabl
rkc 2012/01/06 00:08:01 Done.
+ max = max > min ? max : min + 1;
+ buckets = buckets > 2 ? buckets : 3;
+ // Trim buckets down to a maximum of the given range + over/underflow buckets
+ if ((int)buckets > (max - min + 2)) {
jar (doing other things) 2012/01/05 17:35:14 nit: Use C++ style casts: static_cast<int>(bucket
rkc 2012/01/06 00:08:01 Done.
+ buckets = max - min + 2;
+ }
+
Histogram* counter;
if (type == Histogram::LINEAR_HISTOGRAM) {
counter = LinearHistogram::FactoryGet(name,
« base/metrics/histogram.h ('K') | « base/metrics/histogram.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698