From 55720f372d65aaa14bf6925730f0c715f0179dc5 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Sat, 11 Nov 2023 16:36:39 -0800 Subject: [PATCH] [ruby/openssl] 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] https://github.com/ruby/openssl/commit/07eceb7f63 Co-authored-by: pkuzco Co-authored-by: Kazuki Yamaguchi --- ext/openssl/ossl_pkcs7.c | 6 +++++- test/openssl/test_pkcs7.rb | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ext/openssl/ossl_pkcs7.c b/ext/openssl/ossl_pkcs7.c index cde2ac04a4..aeeb4bf5f4 100644 --- a/ext/openssl/ossl_pkcs7.c +++ b/ext/openssl/ossl_pkcs7.c @@ -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); diff --git a/test/openssl/test_pkcs7.rb b/test/openssl/test_pkcs7.rb index fa15bdbca7..96f3f1f6be 100644 --- a/test/openssl/test_pkcs7.rb +++ b/test/openssl/test_pkcs7.rb @@ -158,6 +158,16 @@ class OpenSSL::TestPKCS7 < OpenSSL::TestCase def test_empty_signed_data_ruby_bug_19974 data = "-----BEGIN PKCS7-----\nMAsGCSqGSIb3DQEHAg==\n-----END PKCS7-----\n" assert_raise(ArgumentError) { OpenSSL::PKCS7.new(data) } + + data = <