Promote warning to exception in ldap_set_rebind_proc()

From now on, ldap_set_rebind_proc() will only accept callable or null
as argument 2.

Closes GH-5763
This commit is contained in:
Paweł Tomulik 2020-06-24 16:14:29 +02:00 committed by Máté Kocsis
parent 30067894fc
commit b3698ed9eb
No known key found for this signature in database
GPG Key ID: FD055E41728BF310
6 changed files with 16 additions and 14 deletions

View File

@ -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

View File

@ -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)
{
@ -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);
@ -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 */

View File

@ -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

View File

@ -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)
@ -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

View File

@ -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)

View File

@ -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