diff options
author | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 22:31:18 +0000 |
---|---|---|
committer | rtenneti@chromium.org <rtenneti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 22:31:18 +0000 |
commit | b122c0cec2b449a0dd126307729249c72a570328 (patch) | |
tree | 338add75446e8fc23e5daf87ea5857902094ac4a /base/metrics | |
parent | 39cc7ab72035866fdcfeb9537a8644f46bdc64cf (diff) | |
download | chromium_src-b122c0cec2b449a0dd126307729249c72a570328.zip chromium_src-b122c0cec2b449a0dd126307729249c72a570328.tar.gz chromium_src-b122c0cec2b449a0dd126307729249c72a570328.tar.bz2 |
Added CHECKs to make sure histogram caller's don't create
histogram that are larger 1G. Added CHECK's to catch bucket_count_
is not corrupted before accessing ranges_ vector.
BUG=73452
TEST=none. histogram unit tests are enough.
Review URL: http://codereview.chromium.org/6542034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75804 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/metrics')
-rw-r--r-- | base/metrics/histogram.cc | 8 | ||||
-rw-r--r-- | base/metrics/histogram.h | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc index a308932..6ac92ed 100644 --- a/base/metrics/histogram.cc +++ b/base/metrics/histogram.cc @@ -23,6 +23,9 @@ namespace base { typedef Histogram::Count Count; +// static +const size_t Histogram::kBucketCount_MAX = 10000u; + scoped_refptr<Histogram> Histogram::FactoryGet(const std::string& name, Sample minimum, Sample maximum, size_t bucket_count, Flags flags) { scoped_refptr<Histogram> histogram(NULL); @@ -413,7 +416,7 @@ size_t Histogram::BucketIndex(Sample value) const { do { DCHECK_GE(over, under); - mid = (over + under)/2; + mid = under + (over - under)/2; if (mid == under) break; if (ranges(mid) <= value) @@ -423,7 +426,7 @@ size_t Histogram::BucketIndex(Sample value) const { } while (true); DCHECK_LE(ranges(mid), value); - DCHECK_GT(ranges(mid+1), value); + CHECK_GT(ranges(mid+1), value); return mid; } @@ -483,6 +486,7 @@ void Histogram::Initialize() { declared_max_ = kSampleType_MAX - 1; DCHECK_LE(declared_min_, declared_max_); DCHECK_GT(bucket_count_, 1u); + CHECK_LT(bucket_count_, kBucketCount_MAX); size_t maximal_bucket_count = declared_max_ - declared_min_ + 2; DCHECK_LE(bucket_count_, maximal_bucket_count); DCHECK_EQ(0, ranges_[0]); diff --git a/base/metrics/histogram.h b/base/metrics/histogram.h index 3bb3f030..2ec56e6 100644 --- a/base/metrics/histogram.h +++ b/base/metrics/histogram.h @@ -241,6 +241,8 @@ class Histogram : public base::RefCountedThreadSafe<Histogram> { typedef int Sample; // Used for samples (and ranges of samples). typedef int Count; // Used to count samples in a bucket. static const Sample kSampleType_MAX = INT_MAX; + // Initialize maximum number of buckets in histograms as 10,000. + static const size_t kBucketCount_MAX; typedef std::vector<Count> Counts; typedef std::vector<Sample> Ranges; |