Skip to content

Commit 1f474fd

Browse files
committed
Merge branch 'PHP-7.1'
Also inline alpn_ctx in openssl_netstream_data (no need for the extra allocation there)
2 parents 712c532 + 7b133e0 commit 1f474fd

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

ext/openssl/xp_ssl.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ typedef struct _php_openssl_netstream_data_t {
141141
php_openssl_sni_cert_t *sni_certs;
142142
unsigned sni_cert_count;
143143
#ifdef HAVE_TLS_ALPN
144-
php_openssl_alpn_ctx *alpn_ctx;
144+
php_openssl_alpn_ctx alpn_ctx;
145145
#endif
146146
char *url_name;
147147
unsigned state_set:1;
@@ -1453,9 +1453,7 @@ static int server_alpn_callback(SSL *ssl_handle, const unsigned char **out, unsi
14531453
{
14541454
php_openssl_netstream_data_t *sslsock = arg;
14551455

1456-
if (SSL_select_next_proto
1457-
((unsigned char **)out, outlen, sslsock->alpn_ctx->data, sslsock->alpn_ctx->len, in,
1458-
inlen) != OPENSSL_NPN_NEGOTIATED) {
1456+
if (SSL_select_next_proto((unsigned char **)out, outlen, sslsock->alpn_ctx.data, sslsock->alpn_ctx.len, in, inlen) != OPENSSL_NPN_NEGOTIATED) {
14591457
return SSL_TLSEXT_ERR_NOACK;
14601458
}
14611459

@@ -1564,9 +1562,8 @@ int php_openssl_setup_crypto(php_stream *stream,
15641562
if (sslsock->is_client) {
15651563
SSL_CTX_set_alpn_protos(sslsock->ctx, alpn, alpn_len);
15661564
} else {
1567-
sslsock->alpn_ctx = (php_openssl_alpn_ctx *) emalloc(sizeof(php_openssl_alpn_ctx));
1568-
sslsock->alpn_ctx->data = (unsigned char*)estrndup((const char*)alpn, alpn_len);
1569-
sslsock->alpn_ctx->len = alpn_len;
1565+
sslsock->alpn_ctx.data = (unsigned char *) pestrndup((const char*)alpn, alpn_len, php_stream_is_persistent(stream));
1566+
sslsock->alpn_ctx.len = alpn_len;
15701567
SSL_CTX_set_alpn_select_cb(sslsock->ctx, server_alpn_callback, sslsock);
15711568
}
15721569

@@ -1597,6 +1594,12 @@ int php_openssl_setup_crypto(php_stream *stream,
15971594
php_error_docref(NULL, E_WARNING, "SSL handle creation failure");
15981595
SSL_CTX_free(sslsock->ctx);
15991596
sslsock->ctx = NULL;
1597+
#ifdef HAVE_TLS_ALPN
1598+
if (sslsock->alpn_ctx.data) {
1599+
pefree(sslsock->alpn_ctx.data, php_stream_is_persistent(stream));
1600+
sslsock->alpn_ctx.data = NULL;
1601+
}
1602+
#endif
16001603
return FAILURE;
16011604
} else {
16021605
SSL_set_ex_data(sslsock->ssl_handle, php_openssl_get_ssl_stream_data_index(), stream);
@@ -2098,6 +2101,11 @@ static int php_openssl_sockop_close(php_stream *stream, int close_handle) /* {{{
20982101
SSL_CTX_free(sslsock->ctx);
20992102
sslsock->ctx = NULL;
21002103
}
2104+
#ifdef HAVE_TLS_ALPN
2105+
if (sslsock->alpn_ctx.data) {
2106+
pefree(sslsock->alpn_ctx.data, php_stream_is_persistent(stream));
2107+
}
2108+
#endif
21012109
#ifdef PHP_WIN32
21022110
if (sslsock->s.socket == -1)
21032111
sslsock->s.socket = SOCK_ERR;

0 commit comments

Comments
 (0)