@@ -3698,7 +3698,7 @@ PHP_FUNCTION(ldap_start_tls)
36983698{
36993699 zval * link ;
37003700 ldap_linkdata * ld ;
3701- int rc , protocol = LDAP_VERSION3 , val = 0 ;
3701+ int rc , protocol = LDAP_VERSION3 ;
37023702
37033703 if (zend_parse_parameters (ZEND_NUM_ARGS (), "O" , & link , ldap_link_ce ) != SUCCESS ) {
37043704 RETURN_THROWS ();
@@ -3707,10 +3707,18 @@ PHP_FUNCTION(ldap_start_tls)
37073707 ld = Z_LDAP_LINK_P (link );
37083708 VERIFY_LDAP_LINK_CONNECTED (ld );
37093709
3710- if (((rc = ldap_set_option (ld -> link , LDAP_OPT_PROTOCOL_VERSION , & protocol )) != LDAP_SUCCESS ) ||
37113710#ifdef LDAP_OPT_X_TLS_NEWCTX
3712- ((rc = ldap_set_option (ld -> link , LDAP_OPT_X_TLS_NEWCTX , & val )) != LDAP_OPT_SUCCESS ) ||
3711+ {
3712+ int val = 0 ;
3713+
3714+ /* ensure all pending TLS options are applied in a new context */
3715+ if (ldap_set_option (ld -> link , LDAP_OPT_X_TLS_NEWCTX , & val ) != LDAP_OPT_SUCCESS ) {
3716+ php_error_docref (NULL , E_WARNING , "Could not create new security context" );
3717+ }
3718+ }
37133719#endif
3720+
3721+ if (((rc = ldap_set_option (ld -> link , LDAP_OPT_PROTOCOL_VERSION , & protocol )) != LDAP_SUCCESS ) ||
37143722 ((rc = ldap_start_tls_s (ld -> link , NULL , NULL )) != LDAP_SUCCESS )
37153723 ) {
37163724 php_error_docref (NULL , E_WARNING ,"Unable to start TLS: %s" , ldap_err2string (rc ));
0 commit comments