Skip to content

Commit 27e11f2

Browse files
jeremyevanspkuzcorhenium
committed
pkcs7: raise ArgumentError for PKCS7 with no content in PKCS7.new
Fixes [Bug #19974] [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 3bdde7d commit 27e11f2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

ext/openssl/ossl_pkcs7.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ ossl_pkcs7_initialize(int argc, VALUE *argv, VALUE self)
346346
BIO_free(in);
347347
if (!p7)
348348
ossl_raise(rb_eArgError, "Could not parse the PKCS7");
349+
if (!p7->d.ptr)
350+
ossl_raise(rb_eArgError, "No content in PKCS7");
349351

350352
RTYPEDDATA_DATA(self) = p7;
351353
PKCS7_free(p7_orig);

test/openssl/test_pkcs7.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ def test_enveloped
155155
assert_equal(data, p7.decrypt(@rsa1024))
156156
end
157157

158+
def test_empty_signed_data_ruby_bug_19974
159+
data = "-----BEGIN PKCS7-----\nMAsGCSqGSIb3DQEHAg==\n-----END PKCS7-----\n"
160+
assert_raise(ArgumentError) { OpenSSL::PKCS7.new(data) }
161+
end
162+
158163
def test_graceful_parsing_failure #[ruby-core:43250]
159164
contents = File.read(__FILE__)
160165
assert_raise(ArgumentError) { OpenSSL::PKCS7.new(contents) }

0 commit comments

Comments
 (0)