Skip to content

Commit 0535fb8

Browse files
ossl config: shareable when frozen
should proobably be initialized as frozen, given no state modifications
1 parent bd647c3 commit 0535fb8

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

ext/openssl/ossl_config.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static const rb_data_type_t ossl_config_type = {
2222
{
2323
0, nconf_free,
2424
},
25-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
25+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FROZEN_SHAREABLE,
2626
};
2727

2828
CONF *
@@ -87,6 +87,7 @@ config_s_parse(VALUE klass, VALUE str)
8787

8888
bio = ossl_obj2bio(&str);
8989
config_load_bio(conf, bio); /* Consumes BIO */
90+
rb_obj_freeze(obj);
9091
return obj;
9192
}
9293

@@ -136,14 +137,15 @@ config_initialize(int argc, VALUE *argv, VALUE self)
136137
VALUE filename;
137138

138139
/* 0-arguments call has no use-case, but is kept for compatibility */
139-
rb_scan_args(argc, argv, "01", &filename);
140140
rb_check_frozen(self);
141+
rb_scan_args(argc, argv, "01", &filename);
141142
if (!NIL_P(filename)) {
142143
BIO *bio = BIO_new_file(StringValueCStr(filename), "rb");
143144
if (!bio)
144145
ossl_raise(eConfigError, "BIO_new_file");
145146
config_load_bio(conf, bio); /* Consumes BIO */
146147
}
148+
rb_obj_freeze(self);
147149
return self;
148150
}
149151

@@ -453,6 +455,6 @@ Init_ossl_config(void)
453455
* The default system configuration file for OpenSSL.
454456
*/
455457
path = CONF_get1_default_config_file();
456-
path_str = ossl_buf2str(path, rb_long2int(strlen(path)));
458+
path_str = rb_obj_freeze(ossl_buf2str(path, rb_long2int(strlen(path))));
457459
rb_define_const(cConfig, "DEFAULT_CONFIG_FILE", path_str);
458460
}

test/openssl/test_config.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ def test_dup
273273
assert_equal(@it.sections.sort, c2.sections.sort)
274274
end
275275

276+
if respond_to?(:ractor)
277+
ractor
278+
def test_ractor
279+
assert Ractor.shareable?(@it)
280+
assert Ractor.shareable?(OpenSSL::Config.parse("[empty]\n"))
281+
assert Ractor.shareable?(OpenSSL::Config::DEFAULT_CONFIG_FILE)
282+
end
283+
end
284+
276285
private
277286

278287
def in_tmpdir(*args)

0 commit comments

Comments
 (0)