]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Only write to pdays/psecs if they are not null
authorNeil Horman <nhorman@openssl.org>
Mon, 8 Dec 2025 18:22:05 +0000 (13:22 -0500)
committerNeil Horman <nhorman@openssl.org>
Tue, 9 Dec 2025 21:02:13 +0000 (16:02 -0500)
We have a few cases in which one of the paramters passed to
ASN1_TIME_diff is null (i.e. the caller doesn't care about the psec
differnce and so passes NULL as that pointer parameter).

However, OPENSSL_gmtime_diff assumes both pointers are valid, and so
writes to them unilaterally resulting in a crash as observed here:
https://github.com/openssl/openssl/pull/29333#issuecomment-3628103959

Check the pointers before writing to them.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Norbert Pocs <norbertp@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/29337)

crypto/asn1/a_time_posix.c

index d65ef1cf8b426fe28d3f93a44619e03153f314e5..4e748007d07c5c1becf7c3ad573a26f182e76950 100644 (file)
@@ -260,8 +260,10 @@ int OPENSSL_gmtime_diff(int *out_days, int *out_secs, const struct tm *from,
     daydiff = timediff / SECS_PER_DAY;
     timediff %= SECS_PER_DAY;
 
-    *out_secs = (int)timediff;
-    *out_days = (int)daydiff;
+    if (out_secs != NULL)
+        *out_secs = (int)timediff;
+    if (out_days != NULL)
+        *out_days = (int)daydiff;
 
     return 1;
 }