diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/asn1/a_time.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c index 8db2163622..574c99bbf8 100644 --- a/src/lib/libcrypto/asn1/a_time.c +++ b/src/lib/libcrypto/asn1/a_time.c | |||
@@ -120,8 +120,8 @@ ASN1_TIME_check(ASN1_TIME *t) | |||
120 | } | 120 | } |
121 | 121 | ||
122 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | 122 | /* Convert an ASN1_TIME structure to GeneralizedTime */ |
123 | ASN1_GENERALIZEDTIME * | 123 | static ASN1_GENERALIZEDTIME * |
124 | ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | 124 | ASN1_TIME_to_generalizedtime_internal(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) |
125 | { | 125 | { |
126 | ASN1_GENERALIZEDTIME *ret; | 126 | ASN1_GENERALIZEDTIME *ret; |
127 | char *str; | 127 | char *str; |
@@ -131,13 +131,7 @@ ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | |||
131 | if (!ASN1_TIME_check(t)) | 131 | if (!ASN1_TIME_check(t)) |
132 | return NULL; | 132 | return NULL; |
133 | 133 | ||
134 | if (!out || !*out) { | 134 | ret = *out; |
135 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) | ||
136 | return NULL; | ||
137 | if (out) | ||
138 | *out = ret; | ||
139 | } else | ||
140 | ret = *out; | ||
141 | 135 | ||
142 | /* If already GeneralizedTime just copy across */ | 136 | /* If already GeneralizedTime just copy across */ |
143 | if (t->type == V_ASN1_GENERALIZEDTIME) { | 137 | if (t->type == V_ASN1_GENERALIZEDTIME) { |
@@ -152,15 +146,38 @@ ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | |||
152 | /* ASN1_STRING_set() allocated 'len + 1' bytes. */ | 146 | /* ASN1_STRING_set() allocated 'len + 1' bytes. */ |
153 | newlen = t->length + 2 + 1; | 147 | newlen = t->length + 2 + 1; |
154 | str = (char *)ret->data; | 148 | str = (char *)ret->data; |
149 | /* XXX ASN1_TIME is not Y2050 compatible */ | ||
155 | i = snprintf(str, newlen, "%s%s", (t->data[0] >= '5') ? "19" : "20", | 150 | i = snprintf(str, newlen, "%s%s", (t->data[0] >= '5') ? "19" : "20", |
156 | (char *) t->data); | 151 | (char *) t->data); |
157 | if (i == -1 || i >= newlen) { | 152 | if (i == -1 || i >= newlen) { |
158 | ASN1_STRING_free(ret); | 153 | M_ASN1_GENERALIZEDTIME_free(ret); |
154 | *out = NULL; | ||
159 | return NULL; | 155 | return NULL; |
160 | } | 156 | } |
161 | return ret; | 157 | return ret; |
162 | } | 158 | } |
163 | 159 | ||
160 | ASN1_GENERALIZEDTIME * | ||
161 | ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | ||
162 | { | ||
163 | ASN1_GENERALIZEDTIME *tmp = NULL, *ret; | ||
164 | |||
165 | if (!out || !*out) { | ||
166 | if (!(tmp = ASN1_GENERALIZEDTIME_new())) | ||
167 | return NULL; | ||
168 | if (out != NULL) | ||
169 | *out = tmp; | ||
170 | else | ||
171 | out = &tmp; | ||
172 | } | ||
173 | |||
174 | ret = ASN1_TIME_to_generalizedtime_internal(t, out); | ||
175 | if (ret == NULL && tmp != NULL) | ||
176 | ASN1_GENERALIZEDTIME_free(tmp); | ||
177 | |||
178 | return ret; | ||
179 | } | ||
180 | |||
164 | int | 181 | int |
165 | ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | 182 | ASN1_TIME_set_string(ASN1_TIME *s, const char *str) |
166 | { | 183 | { |