mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [Patch] statistics: fix buffer overflow in histogram with linear scale
@ 2006-10-20 13:58 Martin Peschke
  2006-10-20 18:52 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Peschke @ 2006-10-20 13:58 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

Values outside the range covered by a histogram with linear
scale resulted in invalid indices pointing to non-existing
'buckets'. Index is adjusted to array boundaries, if required.

Signed-off-by: Martin Peschke <mp3@de.ibm.com>
---

 statistic.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff -urp a/lib/statistic.c b/lib/statistic.c
--- a/lib/statistic.c	2006-10-08 23:03:56.000000000 +0200
+++ b/lib/statistic.c	2006-10-12 19:38:08.000000000 +0200
@@ -994,9 +994,12 @@ static s64 statistic_histogram_calc_valu
 
 static int statistic_histogram_calc_index_lin(struct statistic *stat, s64 value)
 {
-	unsigned long long i = value - stat->u.histogram.range_min;
+	unsigned long long i;
+	if (value <= stat->u.histogram.range_min)
+		return 0;
+	i = value - stat->u.histogram.range_min;
 	do_div(i, stat->u.histogram.base_interval);
-	return i;
+	return min(i, (unsigned long long)(stat->u.histogram.last_index));
 }
 
 static int statistic_histogram_calc_index_log2(struct statistic *stat,



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-10-20 21:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-20 13:58 [Patch] statistics: fix buffer overflow in histogram with linear scale Martin Peschke
2006-10-20 18:52 ` Andrew Morton
2006-10-20 21:15   ` Frank Ch. Eigler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome