You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gentoo-overlay/app-admin/rsyslog/files/8-stable/50-rsyslog-8.16.0-fix-leap-...

87 lines
3.0 KiB

From ffb321f1698a971e0acda48cafa97bb344cf0829 Mon Sep 17 00:00:00 2001
From: Rainer Gerhards <rgerhards@adiscon.com>
Date: Wed, 2 Mar 2016 11:43:09 +0100
Subject: [PATCH] bugfix: unixtimestamp was incorrectly computed
The problem happened in leap year from March til then end
of year and healed itself at the begining of the next year.
During the problem period, the timestamp was 24 hours too
low.
This is primarily a simple fix that can also be applied to
older rsyslog versions. However, we will see if we can
refactor the code to make use of mktime(). Originally, that
was not done for some issues seen, which may no longer
apply.
fixes https://github.com/rsyslog/rsyslog/issues/830
---
runtime/datetime.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/runtime/datetime.c b/runtime/datetime.c
index efb4c81..a07c1b7 100644
--- a/runtime/datetime.c
+++ b/runtime/datetime.c
@@ -1054,6 +1054,11 @@ time_t syslogTime2time_t(struct syslogTime *ts)
MonthInDays = 0; /* any value fits ;) */
break;
}
+ /* adjust for leap years */
+ if((ts->year % 100 != 0 && ts->year % 4 == 0) || (ts->year == 2000)) {
+ if(ts->month > 2)
+ MonthInDays++;
+ }
/* 1) Counting how many Years have passed since 1970
@@ -1064,7 +1069,7 @@ time_t syslogTime2time_t(struct syslogTime *ts)
NumberOfYears = ts->year - yearInSec_startYear - 1;
NumberOfDays = MonthInDays + ts->day - 1;
- TimeInUnixFormat = yearInSecs[NumberOfYears] + NumberOfDays * 86400;
+ TimeInUnixFormat = (yearInSecs[NumberOfYears] + 1) + NumberOfDays * 86400;
/*Add Hours, minutes and seconds */
TimeInUnixFormat += ts->hour*60*60;
From 5cb41f748329986d5e2aa8d5e87f224bb9cb8234 Mon Sep 17 00:00:00 2001
From: Rainer Gerhards <rgerhards@adiscon.com>
Date: Wed, 2 Mar 2016 15:58:18 +0100
Subject: [PATCH] timestamp handling: guard against invalid dates
We do not permit dates outside of the year 1970..2100
interval. Note that network-receivers do already guard
against this, so the new guard only guards against invalid
system time. Still good to have (especially when things are
extended...)
---
runtime/datetime.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/runtime/datetime.c b/runtime/datetime.c
index 9641363..87290c9 100644
--- a/runtime/datetime.c
+++ b/runtime/datetime.c
@@ -1023,6 +1023,13 @@ time_t syslogTime2time_t(struct syslogTime *ts)
int utcOffset;
time_t TimeInUnixFormat;
+ if(ts->year < 1970 || ts->year > 2100) {
+ TimeInUnixFormat = 0;
+ errmsg.LogError(0, RS_RET_ERR, "syslogTime2time_t: invalid year %d "
+ "in timestamp - returning 1970-01-01 instead", ts->year);
+ goto done;
+ }
+
/* Counting how many Days have passed since the 01.01 of the
* selected Year (Month level), according to the selected Month*/
@@ -1096,6 +1103,7 @@ time_t syslogTime2time_t(struct syslogTime *ts)
if(ts->OffsetMode == '+')
utcOffset *= -1; /* if timestamp is ahead, we need to "go back" to UTC */
TimeInUnixFormat += utcOffset;
+done:
return TimeInUnixFormat;
}