Skip to content

Commit 78f03cd

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
2 parents bc32d80 + 5d4846b commit 78f03cd

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

ext/ldap/ldap.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,6 @@ PHP_FUNCTION(ldap_connect)
986986
RETURN_FALSE;
987987
}
988988

989-
object_init_ex(return_value, ldap_link_ce);
990-
ld = Z_LDAP_LINK_P(return_value);
991989

992990
{
993991
int rc = LDAP_SUCCESS;
@@ -1010,13 +1008,17 @@ PHP_FUNCTION(ldap_connect)
10101008

10111009
/* ensure all pending TLS options are applied in a new context */
10121010
if (ldap_set_option(NULL, LDAP_OPT_X_TLS_NEWCTX, &val) != LDAP_OPT_SUCCESS) {
1013-
zval_ptr_dtor(return_value);
1011+
if (url != host) {
1012+
efree(url);
1013+
}
10141014
php_error_docref(NULL, E_WARNING, "Could not create new security context");
10151015
RETURN_FALSE;
10161016
}
10171017
LDAPG(tls_newctx) = false;
10181018
}
10191019
#endif
1020+
object_init_ex(return_value, ldap_link_ce);
1021+
ld = Z_LDAP_LINK_P(return_value);
10201022

10211023
#ifdef LDAP_API_FEATURE_X_OPENLDAP
10221024
/* ldap_init() is deprecated, use ldap_initialize() instead.
@@ -1029,6 +1031,9 @@ PHP_FUNCTION(ldap_connect)
10291031
ldap = ldap_init(host, port);
10301032
if (ldap == NULL) {
10311033
zval_ptr_dtor(return_value);
1034+
if (url != host) {
1035+
efree(url);
1036+
}
10321037
php_error_docref(NULL, E_WARNING, "Could not create session handle");
10331038
RETURN_FALSE;
10341039
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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

0 commit comments

Comments
 (0)