[icinga-checkins] icinga.org: icinga2/master: Fix infinite loop in LegacyTimePeriod:: FindNthWeekday().

git at icinga.org git at icinga.org
Wed May 8 12:49:02 CEST 2013


Module: icinga2
Branch: master
Commit: 36a45059f934c8a8d94903826bf89ce0bd35f5c8
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=36a45059f934c8a8d94903826bf89ce0bd35f5c8

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed May  8 12:48:45 2013 +0200

Fix infinite loop in LegacyTimePeriod::FindNthWeekday().

---

 lib/icinga/legacytimeperiod.cpp |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/icinga/legacytimeperiod.cpp b/lib/icinga/legacytimeperiod.cpp
index 8c49a30..71621fe 100644
--- a/lib/icinga/legacytimeperiod.cpp
+++ b/lib/icinga/legacytimeperiod.cpp
@@ -54,7 +54,17 @@ bool LegacyTimePeriod::IsInTimeRange(tm *begin, tm *end, int stride, tm *referen
 
 void LegacyTimePeriod::FindNthWeekday(int wday, int n, tm *reference)
 {
-	int seen = 0;
+	int dir, seen = 0;
+
+	if (n > 0) {
+		dir = 1;
+	} else {
+		n *= -1;
+		dir = -1;
+
+		/* Negative days are relative to the next month. */
+		reference->tm_mon++;
+	}
 
 	ASSERT(n > 0);
 
@@ -70,7 +80,7 @@ void LegacyTimePeriod::FindNthWeekday(int wday, int n, tm *reference)
 				return;
 		}
 
-		reference->tm_mday++;
+		reference->tm_mday += dir;
 	}
 }
 





More information about the icinga-checkins mailing list