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

Unified Diff: base/metrics/histogram.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
Index: base/metrics/histogram.cc
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc
index a44a2eb8888a517eef35f134737def5d9f46d760..180c36a157a52c35871a5702ce68b65e58df6376 100644
--- a/base/metrics/histogram.cc
+++ b/base/metrics/histogram.cc
@@ -94,6 +94,10 @@ Histogram* Histogram::FactoryGet(const std::string& name,
if (maximum > kSampleType_MAX - 1)
maximum = kSampleType_MAX - 1;
+ DCHECK_GT(maximum, minimum);
+ DCHECK_GT((Sample) bucket_count, 2);
+ DCHECK_LE((Sample) bucket_count, maximum - minimum + 2);
+
if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
// Extra variable is not needed... but this keeps this section basically
// identical to other derived classes in this file (and compiler will
@@ -816,6 +820,10 @@ Histogram* LinearHistogram::FactoryGet(const std::string& name,
if (maximum > kSampleType_MAX - 1)
maximum = kSampleType_MAX - 1;
+ DCHECK_GT(maximum, minimum);
+ DCHECK_GT((Sample) bucket_count, 2);
+ DCHECK_LE((Sample) bucket_count, maximum - minimum + 2);
+
if (!StatisticsRecorder::FindHistogram(name, &histogram)) {
// To avoid racy destruction at shutdown, the following will be leaked.
LinearHistogram* tentative_histogram =

Powered by Google App Engine
This is Rietveld 408576698