Skip to content

Commit 07eceb7

Browse files
jeremyevanspkuzcorhenium
committed
pkcs7: raise PKCS7Error for PKCS7 without content in PKCS7.read_smime
[pkuzco: expanded the fix for other content types] [ky: adjusted formatting and the exception type] Co-authored-by: pkuzco <b.naamneh@gmail.com> Co-authored-by: Kazuki Yamaguchi <k@rhe.jp>
1 parent 27e11f2 commit 07eceb7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ext/openssl/ossl_pkcs7.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
165165
out = NULL;
166166
pkcs7 = SMIME_read_PKCS7(in, &out);
167167
BIO_free(in);
168-
if(!pkcs7) ossl_raise(ePKCS7Error, NULL);
168+
if (!pkcs7)
169+
ossl_raise(ePKCS7Error, "Could not parse the PKCS7");
170+
if (!pkcs7->d.ptr)
171+
ossl_raise(ePKCS7Error, "No content in PKCS7");
172+
169173
data = out ? ossl_membio2str(out) : Qnil;
170174
SetPKCS7(ret, pkcs7);
171175
ossl_pkcs7_set_data(ret, data);

test/openssl/test_pkcs7.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,16 @@ def test_enveloped
158158
def test_empty_signed_data_ruby_bug_19974
159159
data = "-----BEGIN PKCS7-----\nMAsGCSqGSIb3DQEHAg==\n-----END PKCS7-----\n"
160160
assert_raise(ArgumentError) { OpenSSL::PKCS7.new(data) }
161+
162+
data = <<END
163+
MIME-Version: 1.0
164+
Content-Disposition: attachment; filename="smime.p7m"
165+
Content-Type: application/x-pkcs7-mime; smime-type=signed-data; name="smime.p7m"
166+
Content-Transfer-Encoding: base64
167+
168+
#{data}
169+
END
170+
assert_raise(OpenSSL::PKCS7::PKCS7Error) { OpenSSL::PKCS7.read_smime(data) }
161171
end
162172

163173
def test_graceful_parsing_failure #[ruby-core:43250]

0 commit comments

Comments
 (0)