Skip to content

Commit

Permalink
Use ZPP callable check for ldap_set_rebind_proc()
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias committed Aug 13, 2020
1 parent dae83cd commit 96c7d42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
16 changes: 6 additions & 10 deletions ext/ldap/ldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3710,18 +3710,20 @@ int _ldap_rebind_proc(LDAP *ldap, const char *url, ber_tag_t req, ber_int_t msgi
/* {{{ Set a callback function to do re-binds on referral chasing. */
PHP_FUNCTION(ldap_set_rebind_proc)
{
zval *link, *callback;
zval *link;
zend_fcall_info fci;
zend_fcall_info_cache fcc;
ldap_linkdata *ld;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz", &link, &callback) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rf!", &link, &fci, &fcc) == FAILURE) {
RETURN_THROWS();
}

if ((ld = (ldap_linkdata *)zend_fetch_resource(Z_RES_P(link), "ldap link", le_link)) == NULL) {
RETURN_THROWS();
}

if (Z_TYPE_P(callback) == IS_NULL) {
if (!ZEND_FCI_INITIALIZED(fci)) {
/* unregister rebind procedure */
if (!Z_ISUNDEF(ld->rebindproc)) {
zval_ptr_dtor(&ld->rebindproc);
Expand All @@ -3731,20 +3733,14 @@ PHP_FUNCTION(ldap_set_rebind_proc)
RETURN_TRUE;
}

/* callable? */
if (!zend_is_callable(callback, 0, NULL)) {
zend_argument_type_error(2, "must be a valid callback or null, %s given", zend_zval_type_name(callback));
RETURN_THROWS();
}

/* register rebind procedure */
if (Z_ISUNDEF(ld->rebindproc)) {
ldap_set_rebind_proc(ld->link, _ldap_rebind_proc, (void *) link);
} else {
zval_ptr_dtor(&ld->rebindproc);
}

ZVAL_COPY(&ld->rebindproc, callback);
ZVAL_COPY(&ld->rebindproc, &fci.function_name);
RETURN_TRUE;
}
/* }}} */
Expand Down
4 changes: 2 additions & 2 deletions ext/ldap/tests/ldap_set_rebind_proc_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ try {
echo $error->getMessage(), "\n";
}
?>
--EXPECTF--
ldap_set_rebind_proc(): Argument #2 ($callback) must be a valid callback or null, string given
--EXPECT--
ldap_set_rebind_proc(): Argument #2 ($callback) must be a valid callback or null, function "rebind_proc_inexistent" not found or invalid function name

0 comments on commit 96c7d42

Please sign in to comment.