Module: sems Branch: master Commit: 4bd2cdfe73e9e90daeeac0ffa315136531dffc35 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=4bd2cdfe73e9e90daeeac0ffa315136531dffc35
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Thu Sep 6 17:55:55 2012 +0200 b/f: limiting application timers to one year, prevent timer overflows as the timer resolution is uint32_t, and a circular wallclock is used, 31 bits of ticks are actually available for maximum timer values --- core/AmAppTimer.cpp | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/core/AmAppTimer.cpp b/core/AmAppTimer.cpp index 737e2dc..9588319 100644 --- a/core/AmAppTimer.cpp +++ b/core/AmAppTimer.cpp @@ -121,10 +121,21 @@ app_timer* _AmAppTimer::create_timer(const string& q_id, int id, unsigned int ex return timer; } +#define MAX_TIMER_SECONDS 365*24*3600 // one year, well below 1<<31 + void _AmAppTimer::setTimer(const string& eventqueue_name, int timer_id, double timeout) { // microseconds - unsigned int expires = timeout*1000.0*1000.0 / (double)TIMER_RESOLUTION; + unsigned int expires; + if (timeout < 0) { // in the past + expires = 0; + } else if (timeout > MAX_TIMER_SECONDS) { // more than one year + ERROR("Application requesting timer %d for '%s' with timeout %f, " + "clipped to maximum of one year\n", timer_id, eventqueue_name.c_str(), timeout); + expires = (double)MAX_TIMER_SECONDS*1000.0*1000.0 / (double)TIMER_RESOLUTION; + } else { + expires = timeout*1000.0*1000.0 / (double)TIMER_RESOLUTION; + } expires += wall_clock; _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
