ruby-changes:68498
From: Kazuki <ko1@a...>
Date: Sat, 16 Oct 2021 19:53:27 +0900 (JST)
Subject: [ruby-changes:68498] f6612203fa (master): [ruby/openssl] x509stoRe: explicitly call rb_gc_mark() against Store/StoreContext
https://git.ruby-lang.org/ruby.git/commit/?id=f6612203fa From f6612203fa6ea240d83b85aa561258ece11fa48b Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi <k@r...> Date: Thu, 14 Oct 2021 15:52:39 +0900 Subject: [ruby/openssl] x509store: explicitly call rb_gc_mark() against Store/StoreContext We store the reverse reference to the Ruby object in the OpenSSL struct for use from OpenSSL callback functions. To prevent the Ruby object from being relocated by GC.compact, we must "pin" it by calling rb_gc_mark(). https://github.com/ruby/openssl/commit/a6ba9f894f --- ext/openssl/ossl_x509store.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/ext/openssl/ossl_x509store.c b/ext/openssl/ossl_x509store.c index f494dbc908..7c546187c3 100644 --- a/ext/openssl/ossl_x509store.c +++ b/ext/openssl/ossl_x509store.c @@ -112,6 +112,13 @@ VALUE cX509Store; https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509store.c#L112 VALUE cX509StoreContext; VALUE eX509StoreError; +static void +ossl_x509store_mark(void *ptr) +{ + X509_STORE *store = ptr; + rb_gc_mark((VALUE)X509_STORE_get_ex_data(store, store_ex_verify_cb_idx)); +} + static void ossl_x509store_free(void *ptr) { @@ -121,7 +128,7 @@ ossl_x509store_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509store.c#L128 static const rb_data_type_t ossl_x509store_type = { "OpenSSL/X509/STORE", { - 0, ossl_x509store_free, + ossl_x509store_mark, ossl_x509store_free, }, 0, 0, RUBY_TYPED_FREE_IMMEDIATELY, }; @@ -493,23 +500,16 @@ ossl_x509store_verify(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509store.c#L500 return result; } -/* - * Public Functions - */ -static void ossl_x509stctx_free(void*); - - -static const rb_data_type_t ossl_x509stctx_type = { - "OpenSSL/X509/STORE_CTX", - { - 0, ossl_x509stctx_free, - }, - 0, 0, RUBY_TYPED_FREE_IMMEDIATELY, -}; - /* * Private functions */ +static void +ossl_x509stctx_mark(void *ptr) +{ + X509_STORE_CTX *ctx = ptr; + rb_gc_mark((VALUE)X509_STORE_CTX_get_ex_data(ctx, stctx_ex_verify_cb_idx)); +} + static void ossl_x509stctx_free(void *ptr) { @@ -521,6 +521,14 @@ ossl_x509stctx_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509store.c#L521 X509_STORE_CTX_free(ctx); } +static const rb_data_type_t ossl_x509stctx_type = { + "OpenSSL/X509/STORE_CTX", + { + ossl_x509stctx_mark, ossl_x509stctx_free, + }, + 0, 0, RUBY_TYPED_FREE_IMMEDIATELY, +}; + static VALUE ossl_x509stctx_alloc(VALUE klass) { -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/