Skip to content

Commit

Permalink
x509store: emit warning if arguments are given to X509::Store.new
Browse files Browse the repository at this point in the history
Anything passed to OpenSSL::X509::Store.new was always ignored. Let's
emit an explicit warning to not confuse users.
  • Loading branch information
rhenium committed Aug 12, 2020
1 parent fb2fcbb commit d173700
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ext/openssl/ossl_x509store.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ ossl_x509store_initialize(int argc, VALUE *argv, VALUE self)
{
X509_STORE *store;

/* BUG: This method takes any number of arguments but appears to ignore them. */
GetX509Store(self, store);
if (argc != 0)
rb_warn("OpenSSL::X509::Store.new does not take any arguments");
#if !defined(HAVE_OPAQUE_OPENSSL)
/* [Bug #405] [Bug #1678] [Bug #3000]; already fixed? */
store->ex_data.sk = NULL;
Expand Down
21 changes: 13 additions & 8 deletions test/openssl/test_x509store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ def setup
@ee2 = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=EE2")
end

def test_nosegv_on_cleanup
cert = OpenSSL::X509::Certificate.new
store = OpenSSL::X509::Store.new
ctx = OpenSSL::X509::StoreContext.new(store, cert, [])
EnvUtil.suppress_warning do
ctx.cleanup
end
ctx.verify
def test_store_new
# v2.3.0 emits explicit warning
assert_warning(/new does not take any arguments/) {
OpenSSL::X509::Store.new(123)
}
end

def test_add_file_path
Expand Down Expand Up @@ -255,6 +252,14 @@ def test_dup
ctx = OpenSSL::X509::StoreContext.new(store)
assert_raise(NoMethodError) { ctx.dup }
end

def test_ctx_cleanup
# Deprecated in Ruby 1.9.3
cert = OpenSSL::X509::Certificate.new
store = OpenSSL::X509::Store.new
ctx = OpenSSL::X509::StoreContext.new(store, cert, [])
assert_warning(/cleanup/) { ctx.cleanup }
end
end

end

0 comments on commit d173700

Please sign in to comment.