summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto
diff options
context:
space:
mode:
authortb <>2026-08-30 16:52:56 +0000
committertb <>2026-08-30 16:52:56 +0000
commit88ac71e0f8273324409f56626c4c20b5473e8b58 (patch)
tree921774f7e993ce7be4c089add15ab422415b0a40 /src/lib/libcrypto
parentf1d663df044f339b954b1cc4da10dceb9675130e (diff)
downloadopenbsd-88ac71e0f8273324409f56626c4c20b5473e8b58.tar.gz
openbsd-88ac71e0f8273324409f56626c4c20b5473e8b58.tar.bz2
openbsd-88ac71e0f8273324409f56626c4c20b5473e8b58.zip
PKCS7_stream: don't crash on omitted content
Do not access the PKCS7 content union without checking that it's actually populated. Add NULL checks and fail. Whether that's the correct thing to do is dubious, but since this has been broken since the "code" was written a quarter century ago, clearly nobody ever wanted to do that. Match OpenSSL behavior which also means more NULL checks than strictly make sense. CMS_stream() has very similar code, but it's not problematic in this particular way because the content isn't OPTIONAL. Part of a diff from Acts1631
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
index 8712a2ecc1..9ade3df552 100644
--- a/src/lib/libcrypto/pkcs7/pk7_lib.c
+++ b/src/lib/libcrypto/pkcs7/pk7_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_lib.c,v 1.31 2025/05/10 05:54:38 tb Exp $ */ 1/* $OpenBSD: pk7_lib.c,v 1.32 2026/08/30 16:52:56 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -650,6 +650,11 @@ PKCS7_stream(unsigned char ***boundary, PKCS7 *p7)
650 break; 650 break;
651 651
652 case NID_pkcs7_signedAndEnveloped: 652 case NID_pkcs7_signedAndEnveloped:
653 if (p7->d.signed_and_enveloped == NULL ||
654 p7->d.signed_and_enveloped->enc_data == NULL) {
655 PKCS7error(PKCS7_R_NO_CONTENT);
656 break;
657 }
653 os = p7->d.signed_and_enveloped->enc_data->enc_data; 658 os = p7->d.signed_and_enveloped->enc_data->enc_data;
654 if (os == NULL) { 659 if (os == NULL) {
655 os = ASN1_OCTET_STRING_new(); 660 os = ASN1_OCTET_STRING_new();
@@ -658,6 +663,11 @@ PKCS7_stream(unsigned char ***boundary, PKCS7 *p7)
658 break; 663 break;
659 664
660 case NID_pkcs7_enveloped: 665 case NID_pkcs7_enveloped:
666 if (p7->d.enveloped == NULL ||
667 p7->d.enveloped->enc_data == NULL) {
668 PKCS7error(PKCS7_R_NO_CONTENT);
669 break;
670 }
661 os = p7->d.enveloped->enc_data->enc_data; 671 os = p7->d.enveloped->enc_data->enc_data;
662 if (os == NULL) { 672 if (os == NULL) {
663 os = ASN1_OCTET_STRING_new(); 673 os = ASN1_OCTET_STRING_new();
@@ -666,6 +676,10 @@ PKCS7_stream(unsigned char ***boundary, PKCS7 *p7)
666 break; 676 break;
667 677
668 case NID_pkcs7_signed: 678 case NID_pkcs7_signed:
679 if (p7->d.sign == NULL || p7->d.sign->contents == NULL) {
680 PKCS7error(PKCS7_R_NO_CONTENT);
681 break;
682 }
669 os = p7->d.sign->contents->d.data; 683 os = p7->d.sign->contents->d.data;
670 break; 684 break;
671 685