From: Paul Dreik Date: Thu, 7 Dec 2023 15:59:57 +0000 (+0100) Subject: prevent integer overflow in ossl_asn1_time_from_tm X-Git-Tag: openssl-3.3.0-alpha1~280 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5b2d8bc28a8ff59689da98f31459819db09a9099;p=thirdparty%2Fopenssl.git prevent integer overflow in ossl_asn1_time_from_tm this could be triggered by the following code (assuming 64 bit time_t): time_t t = 67768011791126057ULL; ASN1_TIME* at = ASN1_TIME_set(NULL, t); Reviewed-by: Hugo Landau Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/22976) --- diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c index f1702f262ef..931e2854d6d 100644 --- a/crypto/asn1/a_time.c +++ b/crypto/asn1/a_time.c @@ -295,16 +295,22 @@ ASN1_TIME *ossl_asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type) tmps->type = type; p = (char*)tmps->data; - if (type == V_ASN1_GENERALIZEDTIME) + if (ts->tm_mon > INT_MAX - 1) + goto err; + + if (type == V_ASN1_GENERALIZEDTIME) { + if (ts->tm_year > INT_MAX - 1900) + goto err; tmps->length = BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec); - else + } else { tmps->length = BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", ts->tm_year % 100, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec); + } #ifdef CHARSET_EBCDIC ebcdic2ascii(tmps->data, tmps->data, tmps->length);