summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJob Snijders <job@cvs.openbsd.org>2023-08-30 10:13:13 +0000
committerJob Snijders <job@cvs.openbsd.org>2023-08-30 10:13:13 +0000
commit2df2280020697b5530f5174d0ff53f059feaa4d0 (patch)
treeecf72d56a0c67d055c2965fffc221b69fdeb4a85
parentfd7fa8e97e73b84d207c1d53d94b92032139c72d (diff)
Ensure no memory is leaked after passing NULL to ASN1_TIME_normalize()
OK tb@
-rw-r--r--lib/libcrypto/asn1/a_time_tm.c4
-rw-r--r--regress/lib/libcrypto/asn1/asn1time.c5
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 <beck@openbsd.org>
*
@@ -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 <jsing@openbsd.org>
*
@@ -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);
}