From: Paweł Tomulik Date: Wed, 24 Jun 2020 14:14:29 +0000 (+0200) Subject: Promote warning to exception in ldap_set_rebind_proc() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3698ed9eb434ad119bd130fdc3ce4e6be4c0f84;p=php 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 --- diff --git a/UPGRADING b/UPGRADING index ad4c9e30e8..709add579d 100644 --- a/UPGRADING +++ b/UPGRADING @@ -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 diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 1fbfbf59a4..d177b31255 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -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 */ diff --git a/ext/ldap/ldap.stub.php b/ext/ldap/ldap.stub.php index 81a78055bf..4bad9915b8 100644 --- a/ext/ldap/ldap.stub.php +++ b/ext/ldap/ldap.stub.php @@ -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 diff --git a/ext/ldap/ldap_arginfo.h b/ext/ldap/ldap_arginfo.h index 1ecbc2e395..9dcbad54db 100644 --- a/ext/ldap/ldap_arginfo.h +++ b/ext/ldap/ldap_arginfo.h @@ -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 diff --git a/ext/ldap/tests/ldap_set_rebind_proc_basic.phpt b/ext/ldap/tests/ldap_set_rebind_proc_basic.phpt index cc1fc0c313..5c211fc298 100644 --- a/ext/ldap/tests/ldap_set_rebind_proc_basic.phpt +++ b/ext/ldap/tests/ldap_set_rebind_proc_basic.phpt @@ -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) diff --git a/ext/ldap/tests/ldap_set_rebind_proc_error.phpt b/ext/ldap/tests/ldap_set_rebind_proc_error.phpt index 6bede460a4..c12989b15f 100644 --- a/ext/ldap/tests/ldap_set_rebind_proc_error.phpt +++ b/ext/ldap/tests/ldap_set_rebind_proc_error.phpt @@ -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