Skip to content

Commit 5059951

Browse files
HoneyryderChuckrhenium
authored andcommitted
make config frozen on initialize
1 parent 0759018 commit 5059951

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

ext/openssl/ossl_config.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -144,6 +145,7 @@ config_initialize(int argc, VALUE *argv, VALUE self)
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

@@ -158,6 +160,7 @@ config_initialize_copy(VALUE self, VALUE other)
158160
rb_check_frozen(self);
159161
bio = ossl_obj2bio(&str);
160162
config_load_bio(conf, bio); /* Consumes BIO */
163+
rb_obj_freeze(self);
161164
return self;
162165
}
163166

test/openssl/test_config.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def test_s_parse
3939
assert_equal("[ default ]\n\n", c.to_s)
4040
c = OpenSSL::Config.parse(@it.to_s)
4141
assert_equal(['CA_default', 'ca', 'default'], c.sections.sort)
42+
assert_predicate(c, :frozen?)
4243
end
4344

4445
def test_s_parse_format
@@ -188,6 +189,7 @@ def test_initialize
188189
c = OpenSSL::Config.new
189190
assert_equal("", c.to_s)
190191
assert_equal([], c.sections)
192+
assert_predicate(c, :frozen?)
191193
end
192194

193195
def test_initialize_with_empty_file
@@ -268,8 +270,10 @@ def test_inspect
268270
def test_dup
269271
assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
270272
c1 = @it.dup
273+
assert_predicate(c1, :frozen?)
271274
assert_equal(@it.sections.sort, c1.sections.sort)
272275
c2 = @it.clone
276+
assert_predicate(c2, :frozen?)
273277
assert_equal(@it.sections.sort, c2.sections.sort)
274278
end
275279

0 commit comments

Comments
 (0)