]> granicus.if.org Git - php/commitdiff
Fix segfault accessing context when no context assigned
authorDaniel Lowrey <rdlowrey@php.net>
Fri, 14 Feb 2014 17:20:44 +0000 (10:20 -0700)
committerDaniel Lowrey <rdlowrey@php.net>
Fri, 14 Feb 2014 17:24:08 +0000 (10:24 -0700)
ext/openssl/xp_ssl.c

index 523062e0436552e365176fe0b3d152a9f4bdad1d..198dda3842b40974171cb82fa9c60859409b4016 100644 (file)
@@ -452,10 +452,7 @@ static inline int php_openssl_setup_crypto(php_stream *stream,
 }
 
 
-static inline int php_openssl_enable_crypto(php_stream *stream,
-               php_openssl_netstream_data_t *sslsock,
-               php_stream_xport_crypto_param *cparam
-               TSRMLS_DC)
+static inline int php_openssl_enable_crypto(php_stream *stream, php_openssl_netstream_data_t *sslsock, php_stream_xport_crypto_param *cparam TSRMLS_DC)
 {
        int n, retry = 1;
 
@@ -466,11 +463,12 @@ static inline int php_openssl_enable_crypto(php_stream *stream,
                                                has_timeout = 0;
 
 #if OPENSSL_VERSION_NUMBER >= 0x00908070L && !defined(OPENSSL_NO_TLSEXT)
-
+{
                zval **val;
 
-               if (sslsock->is_client
-                       && (php_stream_context_get_option(stream->context, "ssl", "SNI_enabled", &val) == FAILURE
+               if (sslsock->is_client &&
+                       stream->context &&
+                       (php_stream_context_get_option(stream->context, "ssl", "SNI_enabled", &val) == FAILURE
                                || zend_is_true(*val))
                ) {
                        if (php_stream_context_get_option(stream->context, "ssl", "SNI_server_name", &val) == SUCCESS) {
@@ -479,10 +477,13 @@ static inline int php_openssl_enable_crypto(php_stream *stream,
                        } else if (sslsock->url_name) {
                                SSL_set_tlsext_host_name(sslsock->ssl_handle, sslsock->url_name);
                        }
+
+               } else if (sslsock->is_client && !stream->context && sslsock->url_name) {
+                       SSL_set_tlsext_host_name(sslsock->ssl_handle, sslsock->url_name);
                }
 
+}
 #endif
-
                if (!sslsock->state_set) {
                        if (sslsock->is_client) {
                                SSL_set_connect_state(sslsock->ssl_handle);