From 4ee6c374440f88fc23c52ff1b20839fae9890fd0 Mon Sep 17 00:00:00 2001 From: job Date: Wed, 30 Aug 2023 10:13:12 +0000 Subject: [PATCH] Ensure no memory is leaked after passing NULL to ASN1_TIME_normalize() OK tb@ --- lib/libcrypto/asn1/a_time_tm.c | 4 +++- regress/lib/libcrypto/asn1/asn1time.c | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/libcrypto/asn1/a_time_tm.c b/lib/libcrypto/asn1/a_time_tm.c index 9cdac73ff05..556e12a3673 100644 --- a/lib/libcrypto/asn1/a_time_tm.c +++ b/lib/libcrypto/asn1/a_time_tm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_time_tm.c,v 1.29 2023/07/07 19:37:52 beck Exp $ */ +/* $OpenBSD: a_time_tm.c,v 1.30 2023/08/30 10:13:12 job Exp $ */ /* * Copyright (c) 2015 Bob Beck * @@ -610,6 +610,8 @@ ASN1_TIME_normalize(ASN1_TIME *t) { struct tm tm; + if (t == NULL) + return 0; if (!ASN1_TIME_to_tm(t, &tm)) return 0; return tm_to_rfc5280_time(&tm, t) != NULL; diff --git a/regress/lib/libcrypto/asn1/asn1time.c b/regress/lib/libcrypto/asn1/asn1time.c index 0adac08300e..65c36dfb01f 100644 --- a/regress/lib/libcrypto/asn1/asn1time.c +++ b/regress/lib/libcrypto/asn1/asn1time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1time.c,v 1.16 2022/09/05 21:06:31 tb Exp $ */ +/* $OpenBSD: asn1time.c,v 1.17 2023/08/30 10:13:12 job Exp $ */ /* * Copyright (c) 2015 Joel Sing * @@ -528,5 +528,8 @@ main(int argc, char **argv) failed |= asn1_time_test(i, att, V_ASN1_GENERALIZEDTIME); } + /* Check for a leak in ASN1_TIME_normalize(). */ + failed |= ASN1_TIME_normalize(NULL) != 0; + return (failed); } -- 2.20.1