Skip to content

Commit

Permalink
Promote warning to exception in ldap_set_rebind_proc()
Browse files Browse the repository at this point in the history
From now on, ldap_set_rebind_proc() will only accept callable or null
as argument 2.

Closes GH-5763
  • Loading branch information
ptomulik authored and kocsismate committed Jun 30, 2020
1 parent 3006789 commit b3698ed
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ PHP 8.0 UPGRADE NOTES

- LDAP:
. The deprecated function ldap_sort has been removed.
. The interface of ldap_set_rebind_proc has changed; the $callback parameter
does not accept empty string anymore; null value shall be used instead.

- Mbstring:
. The mbstring.func_overload directive has been removed. The related
Expand Down
10 changes: 4 additions & 6 deletions ext/ldap/ldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3736,7 +3736,7 @@ int _ldap_rebind_proc(LDAP *ldap, const char *url, ber_tag_t req, ber_int_t msgi
}
/* }}} */

/* {{{ proto bool ldap_set_rebind_proc(resource link, string callback)
/* {{{ proto bool ldap_set_rebind_proc(resource link, ?callable callback)
Set a callback function to do re-binds on referral chasing. */
PHP_FUNCTION(ldap_set_rebind_proc)
{
Expand All @@ -3751,7 +3751,7 @@ PHP_FUNCTION(ldap_set_rebind_proc)
RETURN_THROWS();
}

if (Z_TYPE_P(callback) == IS_STRING && Z_STRLEN_P(callback) == 0) {
if (Z_TYPE_P(callback) == IS_NULL) {
/* unregister rebind procedure */
if (!Z_ISUNDEF(ld->rebindproc)) {
zval_ptr_dtor(&ld->rebindproc);
Expand All @@ -3763,10 +3763,8 @@ PHP_FUNCTION(ldap_set_rebind_proc)

/* callable? */
if (!zend_is_callable(callback, 0, NULL)) {
zend_string *callback_name = zend_get_callable_name(callback);
php_error_docref(NULL, E_WARNING, "Two arguments expected for '%s' to be a valid callback", ZSTR_VAL(callback_name));
zend_string_release_ex(callback_name, 0);
RETURN_FALSE;
zend_argument_type_error(2, "must be a valid callback or null, %s given", zend_zval_type_name(callback));
RETURN_THROWS();
}

/* register rebind procedure */
Expand Down
3 changes: 1 addition & 2 deletions ext/ldap/ldap.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,8 @@ function ldap_parse_result($link, $result, &$errcode, &$matcheddn = null, &$errm
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
/**
* @param resource $link
* @param callable $callback
*/
function ldap_set_rebind_proc($link, $callback): bool {}
function ldap_set_rebind_proc($link, ?callable $callback): bool {}
#endif

#ifdef HAVE_LDAP_START_TLS_S
Expand Down
4 changes: 2 additions & 2 deletions ext/ldap/ldap_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 53051e130a22dc519676c7a91529d2f9f7d1e6ad */
* Stub hash: c9ce0e98ab386130b6332ae017808bec67b1cd07 */

#if defined(HAVE_ORALDAP)
ZEND_BEGIN_ARG_INFO_EX(arginfo_ldap_connect, 0, 0, 0)
Expand Down Expand Up @@ -280,7 +280,7 @@ ZEND_END_ARG_INFO()
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ldap_set_rebind_proc, 0, 2, _IS_BOOL, 0)
ZEND_ARG_INFO(0, link)
ZEND_ARG_INFO(0, callback)
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 1)
ZEND_END_ARG_INFO()
#endif

Expand Down
2 changes: 1 addition & 1 deletion ext/ldap/tests/ldap_set_rebind_proc_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function rebind_proc ($ds, $ldap_url) {

$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
var_dump(ldap_set_rebind_proc($link, "rebind_proc"));
var_dump(ldap_set_rebind_proc($link, ""));
var_dump(ldap_set_rebind_proc($link, null));
?>
--EXPECT--
bool(true)
Expand Down
9 changes: 6 additions & 3 deletions ext/ldap/tests/ldap_set_rebind_proc_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ function rebind_proc ($ds, $ldap_url) {
}

$link = ldap_connect($host, $port);
var_dump(ldap_set_rebind_proc($link, "rebind_proc_inexistent"));
try {
$result = ldap_set_rebind_proc($link, "rebind_proc_inexistent");
} catch(\TypeError $error) {
echo $error->getMessage(), "\n";
}
?>
--EXPECTF--
Warning: ldap_set_rebind_proc(): Two arguments expected for 'rebind_proc_inexistent' to be a valid callback in %s on line %d
bool(false)
ldap_set_rebind_proc(): Argument #2 ($callback) must be a valid callback or null, string given

0 comments on commit b3698ed

Please sign in to comment.