diff options
author | miod <> | 2014-05-15 21:06:10 +0000 |
---|---|---|
committer | miod <> | 2014-05-15 21:06:10 +0000 |
commit | ce07241b92b5b1b9d60acb439c3d18e00a563d55 (patch) | |
tree | 2b3d3940b1fe2fc1049093e115ce5e85d63e7b4c /src/lib/libcrypto/asn1/a_utctm.c | |
parent | 8bfccde54e4165db2d95797d53f16cb1978af3da (diff) | |
download | openbsd-ce07241b92b5b1b9d60acb439c3d18e00a563d55.tar.gz openbsd-ce07241b92b5b1b9d60acb439c3d18e00a563d55.tar.bz2 openbsd-ce07241b92b5b1b9d60acb439c3d18e00a563d55.zip |
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.
Diffstat (limited to 'src/lib/libcrypto/asn1/a_utctm.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_utctm.c | 29 |
1 files changed, 22 insertions, 7 deletions
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) | |||
149 | return ASN1_UTCTIME_adj(s, t, 0, 0); | 149 | return ASN1_UTCTIME_adj(s, t, 0, 0); |
150 | } | 150 | } |
151 | 151 | ||
152 | ASN1_UTCTIME * | 152 | static ASN1_UTCTIME * |
153 | ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, int offset_day, long offset_sec) | 153 | ASN1_UTCTIME_adj_internal(ASN1_UTCTIME *s, time_t t, int offset_day, |
154 | long offset_sec) | ||
154 | { | 155 | { |
155 | char *p; | 156 | char *p; |
156 | struct tm *ts; | 157 | struct tm *ts; |
157 | struct tm data; | 158 | struct tm data; |
158 | size_t len = 20; | 159 | size_t len = 20; |
159 | 160 | ||
160 | if (s == NULL) | ||
161 | s = M_ASN1_UTCTIME_new(); | ||
162 | if (s == NULL) | ||
163 | return (NULL); | ||
164 | |||
165 | ts = gmtime_r(&t, &data); | 161 | ts = gmtime_r(&t, &data); |
166 | if (ts == NULL) | 162 | if (ts == NULL) |
167 | return (NULL); | 163 | return (NULL); |
@@ -193,6 +189,25 @@ ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, int offset_day, long offset_sec) | |||
193 | return (s); | 189 | return (s); |
194 | } | 190 | } |
195 | 191 | ||
192 | ASN1_UTCTIME * | ||
193 | ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, int offset_day, long offset_sec) | ||
194 | { | ||
195 | ASN1_UTCTIME *tmp = NULL, *ret; | ||
196 | |||
197 | if (s == NULL) { | ||
198 | tmp = M_ASN1_UTCTIME_new(); | ||
199 | if (tmp == NULL) | ||
200 | return NULL; | ||
201 | s = tmp; | ||
202 | } | ||
203 | |||
204 | ret = ASN1_UTCTIME_adj_internal(s, t, offset_day, offset_sec); | ||
205 | if (ret == NULL && tmp != NULL) | ||
206 | M_ASN1_UTCTIME_free(tmp); | ||
207 | |||
208 | return ret; | ||
209 | } | ||
210 | |||
196 | int | 211 | int |
197 | ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) | 212 | ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) |
198 | { | 213 | { |