From e5d5a95f33d73ec3c552c08f29089861335caad5 Mon Sep 17 00:00:00 2001 From: Tony Finch Date: Tue, 13 Sep 2005 18:06:30 +0000 Subject: Fix the handling of reverse time in the ratelimit code. --- src/src/acl.c | 14 +++++++------- src/util/ratelimit.pl | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/src/acl.c b/src/src/acl.c index 06fa6e898..b582df7ea 100644 --- a/src/src/acl.c +++ b/src/src/acl.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/acl.c,v 1.47 2005/09/12 10:08:54 ph10 Exp $ */ +/* $Cambridge: exim/src/src/acl.c,v 1.48 2005/09/13 18:06:30 fanf2 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -2164,16 +2164,16 @@ else + (double)tv.tv_usec / 1000000.0; double prev_time = (double)dbd->time_stamp + (double)dbd->time_usec / 1000000.0; - double interval = this_time - prev_time; - - double i_over_p = interval / period; - double a = exp(-i_over_p); /* We must avoid division by zero, and deal gracefully with the clock going backwards. If we blunder ahead when time is in reverse then the computed - rate will become bogusly huge. Clamp i/p to a very small number instead. */ + rate will be bogus. To be safe we clamp interval to a very small number. */ - if (i_over_p <= 0.0) i_over_p = 1e-9; + double interval = this_time - prev_time <= 0.0 ? 1e-9 + : this_time - prev_time; + + double i_over_p = interval / period; + double a = exp(-i_over_p); dbd->time_stamp = tv.tv_sec; dbd->time_usec = tv.tv_usec; diff --git a/src/util/ratelimit.pl b/src/util/ratelimit.pl index a30cfb60a..bb2abbb5a 100644 --- a/src/util/ratelimit.pl +++ b/src/util/ratelimit.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -wT # -# $Cambridge: exim/src/util/ratelimit.pl,v 1.1 2005/09/13 17:51:06 fanf2 Exp $ +# $Cambridge: exim/src/util/ratelimit.pl,v 1.2 2005/09/13 18:06:31 fanf2 Exp $ use strict; @@ -118,9 +118,9 @@ while (<>) { } # see acl_ratelimit() for details of the following my $interval = $time - $time{$key}; + $interval = 1e-9 if $interval <= 0.0; my $i_over_p = $interval / $period; my $a = exp(-$i_over_p); - $i_over_p = 1e-9 if $i_over_p <= 0.0; $time{$key} = $time; $rate{$key} = $size * (1.0 - $a) / $i_over_p + $a * $rate{$key}; $max{$key} = $rate{$key} if $rate{$key} > $max{$key}; -- cgit v1.2.3