From 1c036c6443af3d0d912f074b0a2c4055c804115c Mon Sep 17 00:00:00 2001 From: Todd Short Date: Wed, 3 May 2017 16:16:51 -0400 Subject: Fix #340: Parse ASN1_TIME to struct tm This works with ASN1_UTCTIME and ASN1_GENERALIZED_TIME Reviewed-by: Rich Salz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/3378) --- crypto/asn1/a_time.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'crypto/asn1') diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c index 46f539cb8d..27f9bc6808 100644 --- a/crypto/asn1/a_time.c +++ b/crypto/asn1/a_time.c @@ -130,20 +130,26 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) return 1; } -static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t) +int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm) { - if (t == NULL) { + if (s == NULL) { time_t now_t; + time(&now_t); + memset(tm, 0, sizeof(*tm)); if (OPENSSL_gmtime(&now_t, tm)) return 1; return 0; } - if (t->type == V_ASN1_UTCTIME) - return asn1_utctime_to_tm(tm, t); - else if (t->type == V_ASN1_GENERALIZEDTIME) - return asn1_generalizedtime_to_tm(tm, t); + if (s->type == V_ASN1_UTCTIME) { + memset(tm, 0, sizeof(*tm)); + return asn1_utctime_to_tm(tm, s); + } + if (s->type == V_ASN1_GENERALIZEDTIME) { + memset(tm, 0, sizeof(*tm)); + return asn1_generalizedtime_to_tm(tm, s); + } return 0; } @@ -152,9 +158,10 @@ int ASN1_TIME_diff(int *pday, int *psec, const ASN1_TIME *from, const ASN1_TIME *to) { struct tm tm_from, tm_to; - if (!asn1_time_to_tm(&tm_from, from)) + + if (!ASN1_TIME_to_tm(from, &tm_from)) return 0; - if (!asn1_time_to_tm(&tm_to, to)) + if (!ASN1_TIME_to_tm(to, &tm_to)) return 0; return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to); } -- cgit v1.2.3