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 committed Nov 25, 2024
1 parent bd647c3 commit b82e38e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion 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 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);
}
2 changes: 2 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

0 comments on commit b82e38e

Please sign in to comment.