summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Minichmayr <markus@tapkey.com>2022-10-10 08:24:38 +0200
committerAllen Winter <allen.winter@kdab.com>2022-10-11 07:53:04 -0400
commitcce20bd051408b00521385c0bfb616ba068450d3 (patch)
treeb5640fd6b9e6137d2f0dd3fb065861cb86ac6f83
parent067da80b9262d569cb774459f38a4254640346fe (diff)
downloadlibical-git-cce20bd051408b00521385c0bfb616ba068450d3.tar.gz
icaltime_as_timet: Support dates staring with year 1902 also for 32-bit time_t. Add a range guard for years from 1902 to 10000 also for 64-bit time_t.
-rw-r--r--src/libical/icaltime.c10
-rw-r--r--src/libical/icaltime.h3
2 files changed, 11 insertions, 2 deletions
diff --git a/src/libical/icaltime.c b/src/libical/icaltime.c
index fe03aee5..b8b0f11b 100644
--- a/src/libical/icaltime.c
+++ b/src/libical/icaltime.c
@@ -120,10 +120,13 @@ static time_t make_time(struct tm *tm, int tzm)
if (tm->tm_mon < 0 || tm->tm_mon > 11)
return ((time_t) - 1);
+ if (tm->tm_year < 2)
+ return ((time_t)-1);
+
#if (SIZEOF_TIME_T == 4)
/* check that year specification within range */
- if (tm->tm_year < 70 || tm->tm_year > 138)
+ if (tm->tm_year > 138)
return ((time_t) - 1);
/* check for upper bound of Jan 17, 2038 (to avoid possibility of
@@ -136,6 +139,11 @@ static time_t make_time(struct tm *tm, int tzm)
return ((time_t) - 1);
}
}
+#else
+ /* We don't support years >= 10000, because the function has not been tested at this range. */
+ if (tm->tm_year >= 8100) {
+ return ((time_t)-1);
+ }
#endif /* SIZEOF_TIME_T */
/*
diff --git a/src/libical/icaltime.h b/src/libical/icaltime.h
index 816eac6f..2de53c9f 100644
--- a/src/libical/icaltime.h
+++ b/src/libical/icaltime.h
@@ -199,7 +199,8 @@ LIBICAL_ICAL_EXPORT struct icaltimetype icaltime_from_day_of_year(const int doy,
* only pass an icaltime in UTC, since no conversion is done. Even in that case,
* it's probably better to just use icaltime_as_timet_with_zone().
*
- * The return value is defined for dates starting with 1902-01-01 until 10000-01-01 (excl.).
+ * The return value is defined for dates ranging from 1902-01-01 (incl.) up to 10000-01-01 (excl.)
+ * if time_t has a size of 64 bit and up to 2038-01-18 (excl.) if it has a size of 32 bit.
*/
LIBICAL_ICAL_EXPORT time_t icaltime_as_timet(const struct icaltimetype);