Skip to content

Commit 5eb68ba

Browse files
committed
ssl: avoid directly storing String object in NPN callback
On the server side, the serialized list of protocols is stored in SSL_CTX as a String object reference. We utilize a hidden instance variable to prevent it from being GC'ed, but this is not enough because it can also be relocated by GC.compact.
1 parent a6ba9f8 commit 5eb68ba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ static int
699699
ssl_npn_advertise_cb(SSL *ssl, const unsigned char **out, unsigned int *outlen,
700700
void *arg)
701701
{
702-
VALUE protocols = (VALUE)arg;
702+
VALUE protocols = rb_attr_get((VALUE)arg, id_npn_protocols_encoded);
703703

704704
*out = (const unsigned char *) RSTRING_PTR(protocols);
705705
*outlen = RSTRING_LENINT(protocols);
@@ -917,7 +917,7 @@ ossl_sslctx_setup(VALUE self)
917917
if (!NIL_P(val)) {
918918
VALUE encoded = ssl_encode_npn_protocols(val);
919919
rb_ivar_set(self, id_npn_protocols_encoded, encoded);
920-
SSL_CTX_set_next_protos_advertised_cb(ctx, ssl_npn_advertise_cb, (void *)encoded);
920+
SSL_CTX_set_next_protos_advertised_cb(ctx, ssl_npn_advertise_cb, (void *)self);
921921
OSSL_Debug("SSL NPN advertise callback added");
922922
}
923923
if (RTEST(rb_attr_get(self, id_i_npn_select_cb))) {

0 commit comments

Comments
 (0)