From 0535fb8ddc6d2db3e2c4e09589201e2adcd6163b Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Sat, 19 Oct 2024 17:14:42 +0100 Subject: [PATCH] ossl config: shareable when frozen should proobably be initialized as frozen, given no state modifications --- ext/openssl/ossl_config.c | 8 +++++--- test/openssl/test_config.rb | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ext/openssl/ossl_config.c b/ext/openssl/ossl_config.c index 203d7ef29..8fffa67ec 100644 --- a/ext/openssl/ossl_config.c +++ b/ext/openssl/ossl_config.c @@ -22,7 +22,7 @@ static const rb_data_type_t ossl_config_type = { { 0, nconf_free, }, - 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED, + 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE, }; CONF * @@ -87,6 +87,7 @@ config_s_parse(VALUE klass, VALUE str) bio = ossl_obj2bio(&str); config_load_bio(conf, bio); /* Consumes BIO */ + rb_obj_freeze(obj); return obj; } @@ -136,14 +137,15 @@ config_initialize(int argc, VALUE *argv, VALUE self) VALUE filename; /* 0-arguments call has no use-case, but is kept for compatibility */ - rb_scan_args(argc, argv, "01", &filename); rb_check_frozen(self); + rb_scan_args(argc, argv, "01", &filename); if (!NIL_P(filename)) { BIO *bio = BIO_new_file(StringValueCStr(filename), "rb"); if (!bio) ossl_raise(eConfigError, "BIO_new_file"); config_load_bio(conf, bio); /* Consumes BIO */ } + rb_obj_freeze(self); return self; } @@ -453,6 +455,6 @@ Init_ossl_config(void) * The default system configuration file for OpenSSL. */ path = CONF_get1_default_config_file(); - path_str = ossl_buf2str(path, rb_long2int(strlen(path))); + path_str = rb_obj_freeze(ossl_buf2str(path, rb_long2int(strlen(path)))); rb_define_const(cConfig, "DEFAULT_CONFIG_FILE", path_str); } diff --git a/test/openssl/test_config.rb b/test/openssl/test_config.rb index 6dbb9c613..776b9788f 100644 --- a/test/openssl/test_config.rb +++ b/test/openssl/test_config.rb @@ -273,6 +273,15 @@ def test_dup assert_equal(@it.sections.sort, c2.sections.sort) end + if respond_to?(:ractor) + ractor + def test_ractor + assert Ractor.shareable?(@it) + assert Ractor.shareable?(OpenSSL::Config.parse("[empty]\n")) + assert Ractor.shareable?(OpenSSL::Config::DEFAULT_CONFIG_FILE) + end + end + private def in_tmpdir(*args)