summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Minichmayr <markus@tapkey.com>2022-10-10 08:24:38 +0200
committerMarkus Minichmayr <markus@tapkey.com>2022-10-10 15:36:51 +0200
commitb821d5f5f4f442827654f0cfb828a0b871f80555 (patch)
tree43f05008a2b9fe1d0c54afadf9756cc8cfc414cc
parentd88b09622acf637b07fa86714f9fad9618f8d6e4 (diff)
downloadlibical-git-b821d5f5f4f442827654f0cfb828a0b871f80555.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.h.cmake3
2 files changed, 11 insertions, 2 deletions
diff --git a/src/libical/icaltime.c b/src/libical/icaltime.c
index 93eebf6c..13213195 100644
--- a/src/libical/icaltime.c
+++ b/src/libical/icaltime.c
@@ -111,10 +111,13 @@ static icaltime_t make_time(struct tm *tm, int tzm)
if (tm->tm_mon < 0 || tm->tm_mon > 11)
return ((icaltime_t) - 1);
+ if (tm->tm_year < 2)
+ return ((icaltime_t)-1);
+
#if (SIZEOF_ICALTIME_T == 4)
/* check that year specification within range */
- if (tm->tm_year < 70 || tm->tm_year > 138)
+ if (tm->tm_year > 138)
return ((icaltime_t) - 1);
/* check for upper bound of Jan 17, 2038 (to avoid possibility of
@@ -127,6 +130,11 @@ static icaltime_t make_time(struct tm *tm, int tzm)
return ((icaltime_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 ((icaltime_t)-1);
+ }
#endif /* SIZEOF_ICALTIME_T */
/*
diff --git a/src/libical/icaltime.h.cmake b/src/libical/icaltime.h.cmake
index b5e93860..bfab1313 100644
--- a/src/libical/icaltime.h.cmake
+++ b/src/libical/icaltime.h.cmake
@@ -191,7 +191,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 icaltime_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 icaltime_t icaltime_as_timet(const struct icaltimetype);