]> granicus.if.org Git - php/commitdiff
Merge branch 'PHP-7.1'
authorBob Weinand <bobwei9@hotmail.com>
Thu, 22 Dec 2016 22:40:24 +0000 (23:40 +0100)
committerBob Weinand <bobwei9@hotmail.com>
Thu, 22 Dec 2016 22:40:24 +0000 (23:40 +0100)
Also inline alpn_ctx in openssl_netstream_data (no need for the extra allocation there)

1  2 
ext/openssl/xp_ssl.c

index 4bd81ae6213c891d80ed62e60bb5fe91b2441177,5515bbafaf6d9afa9da93652d9b7de431af0ef4f..b20a61991220413e2ff723221cb1354511300fc6
@@@ -141,7 -145,7 +141,7 @@@ typedef struct _php_openssl_netstream_d
        php_openssl_sni_cert_t *sni_certs;
        unsigned sni_cert_count;
  #ifdef HAVE_TLS_ALPN
--      php_openssl_alpn_ctx *alpn_ctx;
++      php_openssl_alpn_ctx alpn_ctx;
  #endif
        char *url_name;
        unsigned state_set:1;
@@@ -1453,9 -1457,9 +1453,7 @@@ static int server_alpn_callback(SSL *ss
  {
        php_openssl_netstream_data_t *sslsock = arg;
  
--      if (SSL_select_next_proto
--              ((unsigned char **)out, outlen, sslsock->alpn_ctx->data, sslsock->alpn_ctx->len, in,
--                      inlen) != OPENSSL_NPN_NEGOTIATED) {
++      if (SSL_select_next_proto((unsigned char **)out, outlen, sslsock->alpn_ctx.data, sslsock->alpn_ctx.len, in, inlen) != OPENSSL_NPN_NEGOTIATED) {
                return SSL_TLSEXT_ERR_NOACK;
        }
  
@@@ -1564,9 -1568,9 +1562,8 @@@ int php_openssl_setup_crypto(php_strea
                        if (sslsock->is_client) {
                                SSL_CTX_set_alpn_protos(sslsock->ctx, alpn, alpn_len);
                        } else {
-                               sslsock->alpn_ctx = (php_openssl_alpn_ctx *) emalloc(sizeof(php_openssl_alpn_ctx));
-                               sslsock->alpn_ctx->data = (unsigned char*)estrndup((const char*)alpn, alpn_len);
 -                              sslsock->alpn_ctx = (php_openssl_alpn_ctx *) pemalloc(sizeof(php_openssl_alpn_ctx), php_stream_is_persistent(stream));
 -                              sslsock->alpn_ctx->data = (unsigned char *) pestrndup((const char*)alpn, alpn_len, php_stream_is_persistent(stream));
--                              sslsock->alpn_ctx->len = alpn_len;
++                              sslsock->alpn_ctx.data = (unsigned char *) pestrndup((const char*)alpn, alpn_len, php_stream_is_persistent(stream));
++                              sslsock->alpn_ctx.len = alpn_len;
                                SSL_CTX_set_alpn_select_cb(sslsock->ctx, server_alpn_callback, sslsock);
                        }
  
                php_error_docref(NULL, E_WARNING, "SSL handle creation failure");
                SSL_CTX_free(sslsock->ctx);
                sslsock->ctx = NULL;
 -              if (sslsock->alpn_ctx) {
 -                      pefree(sslsock->alpn_ctx->data, php_stream_is_persistent(stream));
 -                      pefree(sslsock->alpn_ctx, php_stream_is_persistent(stream));
 -                      sslsock->alpn_ctx = NULL;
+ #ifdef HAVE_TLS_ALPN
++              if (sslsock->alpn_ctx.data) {
++                      pefree(sslsock->alpn_ctx.data, php_stream_is_persistent(stream));
++                      sslsock->alpn_ctx.data = NULL;
+               }
+ #endif
                return FAILURE;
        } else {
                SSL_set_ex_data(sslsock->ssl_handle, php_openssl_get_ssl_stream_data_index(), stream);
@@@ -2098,6 -2109,12 +2101,11 @@@ static int php_openssl_sockop_close(php
                        SSL_CTX_free(sslsock->ctx);
                        sslsock->ctx = NULL;
                }
 -              if (sslsock->alpn_ctx) {
 -                      pefree(sslsock->alpn_ctx->data, php_stream_is_persistent(stream));
 -                      pefree(sslsock->alpn_ctx, php_stream_is_persistent(stream));
+ #ifdef HAVE_TLS_ALPN
++              if (sslsock->alpn_ctx.data) {
++                      pefree(sslsock->alpn_ctx.data, php_stream_is_persistent(stream));
+               }
+ #endif
  #ifdef PHP_WIN32
                if (sslsock->s.socket == -1)
                        sslsock->s.socket = SOCK_ERR;