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

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: 2011 -> 2012 Created 8 years, 11 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
« no previous file with comments | « base/metrics/histogram.h ('k') | chrome/browser/extensions/extension_metrics_module.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram.cc
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc
index a44a2eb8888a517eef35f134737def5d9f46d760..a6f2b27b9005eb560cfd5c419acd2692f7d54931 100644
--- a/base/metrics/histogram.cc
+++ b/base/metrics/histogram.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -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 =
« no previous file with comments | « base/metrics/histogram.h ('k') | chrome/browser/extensions/extension_metrics_module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698