summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto
diff options
context:
space:
mode:
authortb <>2026-06-09 12:34:08 +0000
committertb <>2026-06-09 12:34:08 +0000
commit24f1e793923009eb0fb2d073f19bb3af6fcd5ca0 (patch)
tree24564648602215941986daf3876cc13852a64771 /src/lib/libcrypto
parent329187ca76781997d3a01eafa23caac7f93779f7 (diff)
downloadopenbsd-24f1e793923009eb0fb2d073f19bb3af6fcd5ca0.tar.gz
openbsd-24f1e793923009eb0fb2d073f19bb3af6fcd5ca0.tar.bz2
openbsd-24f1e793923009eb0fb2d073f19bb3af6fcd5ca0.zip
Avoid freeing a caller-owned buffer in PKCS7_verify()
If a PKCS#7 S/MIME message comes with an empty set of digestAlgorithms in the SignedData, PKCS7_verify() would incorrectly free a caller-owned buffer. Fix the freeing logic to avoid this situation. From Igor Ustinov via OpenSSL
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_smime.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c
index 9baff7f525..3806d17082 100644
--- a/src/lib/libcrypto/pkcs7/pk7_smime.c
+++ b/src/lib/libcrypto/pkcs7/pk7_smime.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_smime.c,v 1.29 2025/12/20 07:22:43 tb Exp $ */ 1/* $OpenBSD: pk7_smime.c,v 1.30 2026/06/09 12:34:08 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -259,7 +259,7 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
259 char buf[4096]; 259 char buf[4096];
260 int i, j = 0, k, ret = 0; 260 int i, j = 0, k, ret = 0;
261 BIO *p7bio; 261 BIO *p7bio;
262 BIO *tmpin, *tmpout; 262 BIO *next, *tmpin, *tmpout;
263 263
264 if (!p7) { 264 if (!p7) {
265 PKCS7error(PKCS7_R_INVALID_NULL_POINTER); 265 PKCS7error(PKCS7_R_INVALID_NULL_POINTER);
@@ -409,12 +409,12 @@ PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata,
409 409
410 ret = 1; 410 ret = 1;
411 411
412err: 412 err:
413 if (tmpin == indata) { 413 while (p7bio != NULL && p7bio != indata) {
414 if (indata) 414 next = BIO_pop(p7bio);
415 BIO_pop(p7bio); 415 BIO_free(p7bio);
416 p7bio = next;
416 } 417 }
417 BIO_free_all(p7bio);
418 sk_X509_free(signers); 418 sk_X509_free(signers);
419 419
420 return ret; 420 return ret;