50530d
From 30238f96081e47178237e58f5229850514858fd3 Mon Sep 17 00:00:00 2001
50530d
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
50530d
Date: Tue, 15 Nov 2016 06:33:36 +0000
50530d
Subject: [PATCH] merge revision(s) 53064: [Backport #11810]
50530d
50530d
	* ext/openssl/ossl_ssl.c (ssl_npn_select_cb_common): fix parsing
50530d
	  protocol list.
50530d
	  The protocol list from OpenSSL is not null-terminated.
50530d
	  patched by Kazuki Yamaguchi [Bug #11810] [ruby-core:72082]
50530d
50530d
50530d
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@56798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
50530d
---
50530d
 ChangeLog              |  7 +++++++
50530d
 ext/openssl/ossl_ssl.c | 17 +++++++----------
50530d
 2 files changed, 14 insertions(+), 10 deletions(-)
50530d
50530d
diff --git a/ChangeLog b/ChangeLog
50530d
index cae6e73..f8f303e 100644
50530d
--- a/ChangeLog
50530d
+++ b/ChangeLog
50530d
@@ -1,3 +1,10 @@
50530d
+Tue Nov 15 15:29:36 2016  NARUSE, Yui  <naruse@ruby-lang.org>
50530d
+
50530d
+	* ext/openssl/ossl_ssl.c (ssl_npn_select_cb_common): fix parsing
50530d
+	  protocol list.
50530d
+	  The protocol list from OpenSSL is not null-terminated.
50530d
+	  patched by Kazuki Yamaguchi [Bug #11810] [ruby-core:72082]
50530d
+
50530d
 Thu Feb 25 19:49:31 2016  Nobuyoshi Nakada  <nobu@ruby-lang.org>
50530d
 
50530d
 	* ext/socket/socket.c (sock_gethostname): support unlimited size
50530d
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
50530d
index 0da1eb1..5b00cb7 100644
50530d
--- a/ext/openssl/ossl_ssl.c
50530d
+++ b/ext/openssl/ossl_ssl.c
50530d
@@ -605,19 +605,16 @@ ssl_npn_select_cb_common(VALUE cb, const unsigned char **out, unsigned char *out
50530d
 {
50530d
     VALUE selected;
50530d
     long len;
50530d
-    unsigned char l;
50530d
     VALUE protocols = rb_ary_new();
50530d
+    unsigned char l;
50530d
+    const unsigned char *in_end = in + inlen;
50530d
 
50530d
-    /* The format is len_1|proto_1|...|len_n|proto_n\0 */
50530d
-    while (l = *in++) {
50530d
-	VALUE protocol;
50530d
-	if (l > inlen) {
50530d
-	    ossl_raise(eSSLError, "Invalid protocol name list");
50530d
-	}
50530d
-	protocol = rb_str_new((const char *)in, l);
50530d
-	rb_ary_push(protocols, protocol);
50530d
+    /* assume OpenSSL verifies this format */
50530d
+    /* The format is len_1|proto_1|...|len_n|proto_n */
50530d
+    while (in < in_end) {
50530d
+	l = *in++;
50530d
+	rb_ary_push(protocols, rb_str_new((const char *)in, l));
50530d
 	in += l;
50530d
-	inlen -= l;
50530d
     }
50530d
 
50530d
     selected = rb_funcall(cb, rb_intern("call"), 1, protocols);