libc: fix post-2100 infinite-loop on 32-bit

The call of `mktime`/`timegm` with a broken down time after year 2100
led to an infinite-loop on 32bit.

genodelabs/genode#3707
This commit is contained in:
Johannes Schlatow 2023-12-07 15:00:47 +01:00 committed by Norman Feske
parent 74abf8132e
commit 63dd5efa72
2 changed files with 20 additions and 1 deletions

View File

@ -1 +1 @@
dfcf0321f6f20fb8051954bc3fb4e661467a3434
b36b17e21acc3a6b70bc550e19d08abbb15db71a

View File

@ -13,6 +13,25 @@ index 3c66924..05c01ae 100644
for ( ; ; ) {
t = lo / 2 + hi / 2;
if (t < lo)
@@ -1955,14 +2251,14 @@ time2sub(struct tm *const tmp,
} else dir = tmcomp(&mytm, &yourtm);
if (dir != 0) {
if (t == lo) {
- ++t;
- if (t <= lo)
+ if (t == TIME_T_MAX)
return WRONG;
+ ++t;
++lo;
} else if (t == hi) {
- --t;
- if (t >= hi)
+ if (t == TIME_T_MIN)
return WRONG;
+ --t;
--hi;
}
if (lo > hi)
diff --git a/src/lib/libc/contrib/tzcode/stdtime/private.h b/src/lib/libc/contrib/tzcode/stdtime/private.h
index 354a78b..8300ba0 100644
--- src/lib/libc/contrib/tzcode/stdtime/private.h