From ce07241b92b5b1b9d60acb439c3d18e00a563d55 Mon Sep 17 00:00:00 2001 From: miod <> Date: Thu, 15 May 2014 21:06:10 +0000 Subject: Replace ASN1_GENERALIZEDTIME_adj(), ASN1_UTCTIME_adj() and ASN1_TIME_to_generalizedtime() with wrappers around their former implementations, making sure memory allocated is freed in all failure cases. help and ok from beck@ and Brendan MacDonell. --- src/lib/libcrypto/asn1/a_utctm.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/lib/libcrypto/asn1/a_utctm.c') diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c index e4db9f8a99..35f2b7fd66 100644 --- a/src/lib/libcrypto/asn1/a_utctm.c +++ b/src/lib/libcrypto/asn1/a_utctm.c @@ -149,19 +149,15 @@ ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) return ASN1_UTCTIME_adj(s, t, 0, 0); } -ASN1_UTCTIME * -ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, int offset_day, long offset_sec) +static ASN1_UTCTIME * +ASN1_UTCTIME_adj_internal(ASN1_UTCTIME *s, time_t t, int offset_day, + long offset_sec) { char *p; struct tm *ts; struct tm data; size_t len = 20; - if (s == NULL) - s = M_ASN1_UTCTIME_new(); - if (s == NULL) - return (NULL); - ts = gmtime_r(&t, &data); if (ts == NULL) return (NULL); @@ -193,6 +189,25 @@ ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, int offset_day, long offset_sec) return (s); } +ASN1_UTCTIME * +ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, int offset_day, long offset_sec) +{ + ASN1_UTCTIME *tmp = NULL, *ret; + + if (s == NULL) { + tmp = M_ASN1_UTCTIME_new(); + if (tmp == NULL) + return NULL; + s = tmp; + } + + ret = ASN1_UTCTIME_adj_internal(s, t, offset_day, offset_sec); + if (ret == NULL && tmp != NULL) + M_ASN1_UTCTIME_free(tmp); + + return ret; +} + int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) { -- cgit v1.2.3-55-g6feb