From c54714583408c5361dd6e8396b50000c8cf6844f Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 12 Feb 2013 13:23:06 +0100 Subject: [PATCH] Check shift used in freq_est and stats max_count calculation. Signed-off-by: Miroslav Lichvar --- clock.c | 8 ++++++++ port.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/clock.c b/clock.c index 974b37c..e4e4f30 100644 --- a/clock.c +++ b/clock.c @@ -999,11 +999,19 @@ void clock_sync_interval(struct clock *c, int n) shift = c->freq_est_interval - n; if (shift < 0) shift = 0; + else if (shift >= sizeof(int) * 8) { + shift = sizeof(int) * 8 - 1; + pr_warning("freq_est_interval is too long"); + } c->fest.max_count = (1 << shift); shift = c->stats_interval - n; if (shift < 0) shift = 0; + else if (shift >= sizeof(int) * 8) { + shift = sizeof(int) * 8 - 1; + pr_warning("summary_interval is too long"); + } c->stats.max_count = (1 << shift); } diff --git a/port.c b/port.c index 1438808..9899687 100644 --- a/port.c +++ b/port.c @@ -551,6 +551,10 @@ static void port_nrate_initialize(struct port *p) if (shift < 0) shift = 0; + else if (shift >= sizeof(int) * 8) { + shift = sizeof(int) * 8 - 1; + pr_warning("freq_est_interval is too long"); + } /* We start in the 'incapable' state. */ p->pdr_missing = ALLOWED_LOST_RESPONSES + 1;