Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ossl config: shareable when frozen #809

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 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 Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -144,6 +145,7 @@ config_initialize(int argc, VALUE *argv, VALUE self)
ossl_raise(eConfigError, "BIO_new_file");
config_load_bio(conf, bio); /* Consumes BIO */
}
rb_obj_freeze(self);
return self;
}

Expand All @@ -158,6 +160,7 @@ config_initialize_copy(VALUE self, VALUE other)
rb_check_frozen(self);
bio = ossl_obj2bio(&str);
config_load_bio(conf, bio); /* Consumes BIO */
rb_obj_freeze(self);
return self;
}

Expand Down Expand Up @@ -453,6 +456,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);
}
11 changes: 11 additions & 0 deletions test/openssl/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def test_initialize
c = OpenSSL::Config.new
assert_equal("", c.to_s)
assert_equal([], c.sections)
assert c.frozen?
assert c.dup.frozen?
end

def test_initialize_with_empty_file
Expand Down Expand Up @@ -273,6 +275,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)
Expand Down