diff options
author | tb <> | 2021-11-03 13:44:15 +0000 |
---|---|---|
committer | tb <> | 2021-11-03 13:44:15 +0000 |
commit | 3d8791232e97df9ea6bc9b6f8533b6556e5cd3e4 (patch) | |
tree | dc4d2fb58725fbca69758907d792eb299e4b6741 | |
parent | 446bdc00d398da1a5df0e490891dfa0f46829289 (diff) | |
download | openbsd-3d8791232e97df9ea6bc9b6f8533b6556e5cd3e4.tar.gz openbsd-3d8791232e97df9ea6bc9b6f8533b6556e5cd3e4.tar.bz2 openbsd-3d8791232e97df9ea6bc9b6f8533b6556e5cd3e4.zip |
Fix ASN1_TIME_diff() with NULL times
The ASN1_TIME_diff() API accepts NULL ASN1_TIMEs and interprets them
as "now". This is used in sysutils/monit, as found by semarie with a
crash after update. Implement this behavior by porting a version of
ASN1_TIME_to_tm() to LibreSSL and using it in ASN1_TIME_diff().
Tested by semarie
ok beck jsing semarie
-rw-r--r-- | src/lib/libcrypto/asn1/a_time.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c index aa6f1c0773..6e4f1a8065 100644 --- a/src/lib/libcrypto/asn1/a_time.c +++ b/src/lib/libcrypto/asn1/a_time.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_time.c,v 1.30 2021/10/28 14:24:08 tb Exp $ */ | 1 | /* $OpenBSD: a_time.c,v 1.31 2021/11/03 13:44:15 tb Exp $ */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
@@ -106,14 +106,29 @@ ASN1_TIME_free(ASN1_TIME *a) | |||
106 | ASN1_item_free((ASN1_VALUE *)a, &ASN1_TIME_it); | 106 | ASN1_item_free((ASN1_VALUE *)a, &ASN1_TIME_it); |
107 | } | 107 | } |
108 | 108 | ||
109 | /* Public API in OpenSSL. Kept internal for now. */ | ||
110 | static int | ||
111 | ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm) | ||
112 | { | ||
113 | time_t now; | ||
114 | |||
115 | if (s != NULL) | ||
116 | return ASN1_time_parse(s->data, s->length, tm, 0) != -1; | ||
117 | |||
118 | time(&now); | ||
119 | memset(tm, 0, sizeof(*tm)); | ||
120 | |||
121 | return gmtime_r(&now, tm) != NULL; | ||
122 | } | ||
123 | |||
109 | int | 124 | int |
110 | ASN1_TIME_diff(int *pday, int *psec, const ASN1_TIME *from, const ASN1_TIME *to) | 125 | ASN1_TIME_diff(int *pday, int *psec, const ASN1_TIME *from, const ASN1_TIME *to) |
111 | { | 126 | { |
112 | struct tm tm_from, tm_to; | 127 | struct tm tm_from, tm_to; |
113 | 128 | ||
114 | if (ASN1_time_parse(from->data, from->length, &tm_from, 0) == -1) | 129 | if (!ASN1_TIME_to_tm(from, &tm_from)) |
115 | return 0; | 130 | return 0; |
116 | if (ASN1_time_parse(to->data, to->length, &tm_to, 0) == -1) | 131 | if (!ASN1_TIME_to_tm(to, &tm_to)) |
117 | return 0; | 132 | return 0; |
118 | 133 | ||
119 | return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to); | 134 | return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to); |