summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllen Winter <allen.winter@kdab.com>2022-10-11 09:04:02 -0400
committerAllen Winter <allen.winter@kdab.com>2022-10-11 09:05:13 -0400
commit19d8ee6278da432fe3e71f18b270653ce34f8fb6 (patch)
tree7c33e8f4ddab2f1c2778f944783d7c24e414fd9a
parent0c5af4c85de1937ac8d9e2668b2e4e74810998da (diff)
parent464c22c2236c1266194cf38e7ec14ab17d2fc8f7 (diff)
downloadlibical-git-19d8ee6278da432fe3e71f18b270653ce34f8fb6.tar.gz
Merge branch '3.0'
-rw-r--r--ReleaseNotes.txt1
-rw-r--r--src/libical/icaltime.c10
-rw-r--r--src/libical/icaltime.h.cmake3
-rw-r--r--src/test/regression.c32
4 files changed, 44 insertions, 2 deletions
diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt
index 3e53453d..3d17b784 100644
--- a/ReleaseNotes.txt
+++ b/ReleaseNotes.txt
@@ -57,6 +57,7 @@ Version 3.1.0 (NOT RELEASED YET):
Version 3.0.16 (UNRELEASED):
----------------------------
* Fix a regression in 3.0.15 that limited how many lines could be processed in one call to icalparser_parse()
+ * Fix argument guards in icaltime_as_timet to match documentation and tests.
Version 3.0.15 (06 October 2022):
---------------------------------
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..cf9f2688 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 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 icaltime_t icaltime_as_timet(const struct icaltimetype);
diff --git a/src/test/regression.c b/src/test/regression.c
index 4dfe2a19..3d02469e 100644
--- a/src/test/regression.c
+++ b/src/test/regression.c
@@ -5250,6 +5250,11 @@ static void test_comma_in_xproperty(void)
void test_icaltime_as_timet(void)
{
+ icaltimetype tt;
+ time_t expectedTimeT;
+
+ ok("icaltime_from_string translates 19011231T235959Z to -1", icaltime_as_timet(icaltime_from_string("19011231T235959Z")) == -1);
+
ok("icaltime_from_string translates 19020101T000000Z to -2145916800", icaltime_as_timet(icaltime_from_string("19020101T000000Z")) == -2145916800);
ok("icaltime_from_string translates 19290519T000000Z to -1281916800", icaltime_as_timet(icaltime_from_string("19290519T000000Z")) == -1281916800);
ok("icaltime_from_string translates 19561004T000000Z to -417916800", icaltime_as_timet(icaltime_from_string("19561004T000000Z")) == -417916800);
@@ -5268,7 +5273,34 @@ void test_icaltime_as_timet(void)
ok("icaltime_from_string translates 25101107T235959Z to 17067628799", icaltime_as_timet(icaltime_from_string("25101107T235959Z")) == 17067628799);
ok("icaltime_from_string translates 25821231T235959Z to 19344441599", icaltime_as_timet(icaltime_from_string("25821231T235959Z")) == 19344441599);
ok("icaltime_from_string translates 99991231T235959Z to 253402300799", icaltime_as_timet(icaltime_from_string("99991231T235959Z")) == 253402300799);
+
+ tt = icaltime_from_string("99991231T235959Z");
+ icaltime_adjust(&tt, 0, 0, 0, 1);
+ ok("icaltime_from_string translates 100000101T000000Z to -1", icaltime_as_timet(tt) == -1);
+#else
+ ok("icaltime_from_string translates 20380118T000000Z to -1", icaltime_as_timet(icaltime_from_string("20380118T000000Z")) == -1);
#endif
+
+ tt = icaltime_from_string("19020101T000000Z");
+ expectedTimeT = -2145916800;
+
+#if (SIZEOF_TIME_T > 4)
+ // Going through each day until 10000 takes ~250ms on a reasonably powered year 2020 business laptop.
+ while (tt.year < 10000)
+#else
+ while ((tt.year < 2038) || ((tt.year == 2038) && (tt.month == 1) && (tt.day <= 17)))
+#endif
+ {
+ time_t actualTimeT = icaltime_as_timet(tt);
+ if (actualTimeT != expectedTimeT) {
+ ok("icaltime_as_timet translates correctly", actualTimeT == expectedTimeT);
+ }
+
+ icaltime_adjust(&tt, 1, 0, 0, 0);
+ expectedTimeT += (24 * 60 * 60);
+ }
+
+ ok("icaltime_as_timet translates out of bounds correctly", icaltime_as_timet(tt) == -1);
}
void test_icalcomponent_with_lastmodified(void)