Skip to content

Commit

Permalink
ossl config: shareable when frozen
Browse files Browse the repository at this point in the history
should proobably be initialized as frozen, given no state modifications
  • Loading branch information
HoneyryderChuck committed Nov 12, 2024
1 parent bd647c3 commit fd3b246
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ext/openssl/ossl_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -47,6 +47,7 @@ config_s_alloc(VALUE klass)
if (!conf)
ossl_raise(eConfigError, "NCONF_new");
RTYPEDDATA_DATA(obj) = conf;
rb_obj_freeze(obj);
return obj;
}

Expand Down Expand Up @@ -137,7 +138,6 @@ config_initialize(int argc, VALUE *argv, VALUE self)

/* 0-arguments call has no use-case, but is kept for compatibility */
rb_scan_args(argc, argv, "01", &filename);
rb_check_frozen(self);
if (!NIL_P(filename)) {
BIO *bio = BIO_new_file(StringValueCStr(filename), "rb");
if (!bio)
Expand Down Expand Up @@ -453,6 +453,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);
}
8 changes: 8 additions & 0 deletions test/openssl/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ def test_dup
assert_equal(@it.sections.sort, c2.sections.sort)
end

if respond_to?(:ractor)
ractor
def test_ractor
assert Ractor.shareable?(OpenSSL::Config.parse("[empty]\n"))
assert Ractor.shareable?(OpenSSL::Config::DEFAULT_CONFIG_FILE)
end
end

private

def in_tmpdir(*args)
Expand Down

0 comments on commit fd3b246

Please sign in to comment.