Fix an integer overflow in o_time.c
authorjwalch <jeremy.walch@gmail.com>
Fri, 19 Feb 2021 18:02:27 +0000 (13:02 -0500)
committerPauli <ppzgs1@gmail.com>
Wed, 24 Feb 2021 22:39:07 +0000 (08:39 +1000)
If input offset_sec is sufficiently large (> INT32_MAX * SECS_PER_DAY, which is possible for a long on 64-bit platforms), then the first assignment contains an overflow.

I think leaving offset_hms as an int is still safe.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14252)

crypto/o_time.c

index 632e19e3679a88fe30cc546f55459c21b142c86e..f367945a1806523cda995af3e39dbd202bbd19ef 100644 (file)
@@ -133,8 +133,8 @@ int OPENSSL_gmtime_diff(int *pday, int *psec,
 static int julian_adj(const struct tm *tm, int off_day, long offset_sec,
                       long *pday, int *psec)
 {
-    int offset_hms, offset_day;
-    long time_jd;
+    int offset_hms;
+    long offset_day, time_jd;
     int time_year, time_month, time_day;
     /* split offset into days and day seconds */
     offset_day = offset_sec / SECS_PER_DAY;