aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/asn1
diff options
context:
space:
mode:
authorTodd Short <tshort@akamai.com>2017-05-03 16:16:51 -0400
committerMatt Caswell <matt@openssl.org>2017-06-08 13:19:13 +0100
commit1c036c6443af3d0d912f074b0a2c4055c804115c (patch)
tree68c32c7483c11022fb4c5a6b8253501f57fcdcc9 /crypto/asn1
parent95dd5fb21427d32272e05ce94d0769d55861fc8b (diff)
downloadopenssl-1c036c6443af3d0d912f074b0a2c4055c804115c.tar.gz
Fix #340: Parse ASN1_TIME to struct tm
This works with ASN1_UTCTIME and ASN1_GENERALIZED_TIME Reviewed-by: Rich Salz <rsalz@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/3378)
Diffstat (limited to 'crypto/asn1')
-rw-r--r--crypto/asn1/a_time.c23
1 files changed, 15 insertions, 8 deletions
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);
}