Skip to content

Commit

Permalink
pkcs7: raise PKCS7Error for PKCS7 without content in PKCS7.read_smime
Browse files Browse the repository at this point in the history
[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>
  • Loading branch information
3 people committed Apr 30, 2024
1 parent 27e11f2 commit 07eceb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ext/openssl/ossl_pkcs7.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
out = NULL;
pkcs7 = SMIME_read_PKCS7(in, &out);
BIO_free(in);
if(!pkcs7) ossl_raise(ePKCS7Error, NULL);
if (!pkcs7)
ossl_raise(ePKCS7Error, "Could not parse the PKCS7");
if (!pkcs7->d.ptr)
ossl_raise(ePKCS7Error, "No content in PKCS7");

data = out ? ossl_membio2str(out) : Qnil;
SetPKCS7(ret, pkcs7);
ossl_pkcs7_set_data(ret, data);
Expand Down
10 changes: 10 additions & 0 deletions test/openssl/test_pkcs7.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ def test_enveloped
def test_empty_signed_data_ruby_bug_19974
data = "-----BEGIN PKCS7-----\nMAsGCSqGSIb3DQEHAg==\n-----END PKCS7-----\n"
assert_raise(ArgumentError) { OpenSSL::PKCS7.new(data) }

data = <<END
MIME-Version: 1.0
Content-Disposition: attachment; filename="smime.p7m"
Content-Type: application/x-pkcs7-mime; smime-type=signed-data; name="smime.p7m"
Content-Transfer-Encoding: base64
#{data}
END
assert_raise(OpenSSL::PKCS7::PKCS7Error) { OpenSSL::PKCS7.read_smime(data) }
end

def test_graceful_parsing_failure #[ruby-core:43250]
Expand Down

0 comments on commit 07eceb7

Please sign in to comment.