File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -1011,8 +1011,6 @@ PHP_FUNCTION(ldap_connect)
10111011 RETURN_FALSE ;
10121012 }
10131013
1014- object_init_ex (return_value , ldap_link_ce );
1015- ld = Z_LDAP_LINK_P (return_value );
10161014
10171015 {
10181016 int rc = LDAP_SUCCESS ;
@@ -1035,13 +1033,17 @@ PHP_FUNCTION(ldap_connect)
10351033
10361034 /* ensure all pending TLS options are applied in a new context */
10371035 if (ldap_set_option (NULL , LDAP_OPT_X_TLS_NEWCTX , & val ) != LDAP_OPT_SUCCESS ) {
1038- zval_ptr_dtor (return_value );
1036+ if (url != host ) {
1037+ efree (url );
1038+ }
10391039 php_error_docref (NULL , E_WARNING , "Could not create new security context" );
10401040 RETURN_FALSE ;
10411041 }
10421042 LDAPG (tls_newctx ) = false;
10431043 }
10441044#endif
1045+ object_init_ex (return_value , ldap_link_ce );
1046+ ld = Z_LDAP_LINK_P (return_value );
10451047
10461048#ifdef LDAP_API_FEATURE_X_OPENLDAP
10471049 /* ldap_init() is deprecated, use ldap_initialize() instead.
@@ -1054,6 +1056,9 @@ PHP_FUNCTION(ldap_connect)
10541056 ldap = ldap_init (host , port );
10551057 if (ldap == NULL ) {
10561058 zval_ptr_dtor (return_value );
1059+ if (url != host ) {
1060+ efree (url );
1061+ }
10571062 php_error_docref (NULL , E_WARNING , "Could not create session handle" );
10581063 RETURN_FALSE ;
10591064 }
Original file line number Diff line number Diff line change 1+ --TEST--
2+ ldap_connect() - Connection errors
3+ --EXTENSIONS--
4+ ldap
5+ --INI--
6+ error_reporting=E_ALL & ~E_DEPRECATED
7+ --FILE--
8+ <?php
9+ require "connect.inc " ;
10+ try {
11+ ldap_connect ("nope:// $ host " , 65536 );
12+ } catch (\ValueError $ e ) {
13+ echo $ e ->getMessage (), PHP_EOL ;
14+ }
15+
16+ try {
17+ ldap_connect ("nope:// $ host " , 0 );
18+ } catch (\ValueError $ e ) {
19+ echo $ e ->getMessage (), PHP_EOL ;
20+ }
21+ ?>
22+ --EXPECT--
23+ ldap_connect(): Argument #2 ($port) must be between 1 and 65535
24+ ldap_connect(): Argument #2 ($port) must be between 1 and 65535
You can’t perform that action at this time.
0 commit comments