diff options
Diffstat (limited to 'src/lib/libcrypto/pkcs7/pk7_smime.c')
-rw-r--r-- | src/lib/libcrypto/pkcs7/pk7_smime.c | 46 |
1 files changed, 8 insertions, 38 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c index a852b49235..6e5735de11 100644 --- a/src/lib/libcrypto/pkcs7/pk7_smime.c +++ b/src/lib/libcrypto/pkcs7/pk7_smime.c | |||
@@ -155,7 +155,7 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, | |||
155 | char buf[4096]; | 155 | char buf[4096]; |
156 | int i, j=0, k, ret = 0; | 156 | int i, j=0, k, ret = 0; |
157 | BIO *p7bio; | 157 | BIO *p7bio; |
158 | BIO *tmpin, *tmpout; | 158 | BIO *tmpout; |
159 | 159 | ||
160 | if(!p7) { | 160 | if(!p7) { |
161 | PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_INVALID_NULL_POINTER); | 161 | PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_INVALID_NULL_POINTER); |
@@ -228,30 +228,7 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, | |||
228 | /* Check for revocation status here */ | 228 | /* Check for revocation status here */ |
229 | } | 229 | } |
230 | 230 | ||
231 | /* Performance optimization: if the content is a memory BIO then | 231 | p7bio=PKCS7_dataInit(p7,indata); |
232 | * store its contents in a temporary read only memory BIO. This | ||
233 | * avoids potentially large numbers of slow copies of data which will | ||
234 | * occur when reading from a read write memory BIO when signatures | ||
235 | * are calculated. | ||
236 | */ | ||
237 | |||
238 | if (indata && (BIO_method_type(indata) == BIO_TYPE_MEM)) | ||
239 | { | ||
240 | char *ptr; | ||
241 | long len; | ||
242 | len = BIO_get_mem_data(indata, &ptr); | ||
243 | tmpin = BIO_new_mem_buf(ptr, len); | ||
244 | if (tmpin == NULL) | ||
245 | { | ||
246 | PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE); | ||
247 | return 0; | ||
248 | } | ||
249 | } | ||
250 | else | ||
251 | tmpin = indata; | ||
252 | |||
253 | |||
254 | p7bio=PKCS7_dataInit(p7,tmpin); | ||
255 | 232 | ||
256 | if(flags & PKCS7_TEXT) { | 233 | if(flags & PKCS7_TEXT) { |
257 | if(!(tmpout = BIO_new(BIO_s_mem()))) { | 234 | if(!(tmpout = BIO_new(BIO_s_mem()))) { |
@@ -293,15 +270,9 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, | |||
293 | ret = 1; | 270 | ret = 1; |
294 | 271 | ||
295 | err: | 272 | err: |
296 | |||
297 | if (tmpin == indata) | ||
298 | { | ||
299 | if(indata) BIO_pop(p7bio); | ||
300 | BIO_free_all(p7bio); | ||
301 | } | ||
302 | else | ||
303 | BIO_free_all(tmpin); | ||
304 | 273 | ||
274 | if(indata) BIO_pop(p7bio); | ||
275 | BIO_free_all(p7bio); | ||
305 | sk_X509_free(signers); | 276 | sk_X509_free(signers); |
306 | 277 | ||
307 | return ret; | 278 | return ret; |
@@ -325,6 +296,10 @@ STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags) | |||
325 | PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE); | 296 | PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE); |
326 | return NULL; | 297 | return NULL; |
327 | } | 298 | } |
299 | if(!(signers = sk_X509_new_null())) { | ||
300 | PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,ERR_R_MALLOC_FAILURE); | ||
301 | return NULL; | ||
302 | } | ||
328 | 303 | ||
329 | /* Collect all the signers together */ | 304 | /* Collect all the signers together */ |
330 | 305 | ||
@@ -335,11 +310,6 @@ STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags) | |||
335 | return 0; | 310 | return 0; |
336 | } | 311 | } |
337 | 312 | ||
338 | if(!(signers = sk_X509_new_null())) { | ||
339 | PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,ERR_R_MALLOC_FAILURE); | ||
340 | return NULL; | ||
341 | } | ||
342 | |||
343 | for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++) | 313 | for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++) |
344 | { | 314 | { |
345 | si = sk_PKCS7_SIGNER_INFO_value(sinfos, i); | 315 | si = sk_PKCS7_SIGNER_INFO_value(sinfos, i); |