Skip to content

Commit

Permalink
make config frozen on initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
HoneyryderChuck authored and rhenium committed Dec 7, 2024
1 parent 0759018 commit 5059951
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/openssl/ossl_config.c
Original file line number Diff line number Diff line change
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
4 changes: 4 additions & 0 deletions test/openssl/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_s_parse
assert_equal("[ default ]\n\n", c.to_s)
c = OpenSSL::Config.parse(@it.to_s)
assert_equal(['CA_default', 'ca', 'default'], c.sections.sort)
assert_predicate(c, :frozen?)
end

def test_s_parse_format
Expand Down Expand Up @@ -188,6 +189,7 @@ def test_initialize
c = OpenSSL::Config.new
assert_equal("", c.to_s)
assert_equal([], c.sections)
assert_predicate(c, :frozen?)
end

def test_initialize_with_empty_file
Expand Down Expand Up @@ -268,8 +270,10 @@ def test_inspect
def test_dup
assert_equal(['CA_default', 'ca', 'default'], @it.sections.sort)
c1 = @it.dup
assert_predicate(c1, :frozen?)
assert_equal(@it.sections.sort, c1.sections.sort)
c2 = @it.clone
assert_predicate(c2, :frozen?)
assert_equal(@it.sections.sort, c2.sections.sort)
end

Expand Down

0 comments on commit 5059951

Please sign in to comment.