From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 2855E1960022 for ; Wed, 15 Jul 2015 11:35:20 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [133.44.2.201]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 30C7FB5D8DE for ; Wed, 15 Jul 2015 12:03:49 +0900 (JST) Received: from funfun.nagaokaut.ac.jp (localhost.nagaokaut.ac.jp [127.0.0.1]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 7F56B97A826 for ; Wed, 15 Jul 2015 12:03:50 +0900 (JST) X-Virus-Scanned: amavisd-new at nagaokaut.ac.jp Received: from funfun.nagaokaut.ac.jp ([127.0.0.1]) by funfun.nagaokaut.ac.jp (funfun.nagaokaut.ac.jp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oTdJogJpmdjg for ; Wed, 15 Jul 2015 12:03:50 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by funfun.nagaokaut.ac.jp (Postfix) with ESMTP id 5E71A97A838 for ; Wed, 15 Jul 2015 12:03:50 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 088BA95243A for ; Wed, 15 Jul 2015 12:03:48 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id DDB4F12047D; Wed, 15 Jul 2015 12:03:47 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by neon.ruby-lang.org (Postfix) with ESMTP id B251F120477 for ; Wed, 15 Jul 2015 12:03:43 +0900 (JST) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 24CDE640011; Wed, 15 Jul 2015 03:03:42 +0000 (UTC) Date: Wed, 15 Jul 2015 03:03:41 +0000 From: Eric Wong To: Ruby developers Message-ID: <20150715030341.GB20332@dcvr.yhbt.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-ML-Name: ruby-core X-Mail-Count: 69975 Subject: [ruby-core:69975] Re: [Ruby trunk - Feature #9390] Support for the ALPN TLS extension X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" tenderlove@ruby-lang.org wrote: > +ssl_alpn_select_cb(SSL *ssl, const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg) > +{ > + int i = 0; > + VALUE sslctx_obj, cb, protocols, selected; > + > + sslctx_obj = (VALUE) arg; > + cb = rb_iv_get(sslctx_obj, "@alpn_select_cb"); > + protocols = rb_ary_new(); > + > + /* The format is len_1|proto_1|...|len_n|proto_n\0 */ > + while (in[i]) { > + VALUE protocol = rb_str_new((const char *) &in[i + 1], in[i]); > + rb_ary_push(protocols, protocol); > + i += in[i] + 1; > + } > + > + selected = rb_funcall(cb, rb_intern("call"), 1, protocols); > + StringValue(selected); > + *out = (unsigned char *) StringValuePtr(selected); > + *outlen = RSTRING_LENINT(selected); I think we need to keep `selected' markable by GC as long as anything may use `out'. Otherwise `out' can refer to a freed region. Perhaps add the following here: rb_iv_set(sslctx_obj, "@_alpn_selected", selected); Side note: StringValue is redundant if using StringValuePtr Haven't looked at the rest closely, but that jumped out at me.