Skip to content

Commit

Permalink
ext/ldap: Move server controls check prior to allocating modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Girgias committed Sep 25, 2024
1 parent cf240ea commit 46a0773
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions ext/ldap/ldap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,7 @@ PHP_FUNCTION(ldap_delete_ext)
/* {{{ Perform multiple modifications as part of one operation */
PHP_FUNCTION(ldap_modify_batch)
{
zval *serverctrls = NULL;
zval *server_controls_zv = NULL;
zval *link;
char *dn;
size_t dn_len;
Expand Down Expand Up @@ -2525,7 +2525,7 @@ PHP_FUNCTION(ldap_modify_batch)
];
*/

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Osh/|a!", &link, ldap_link_ce, &dn, &dn_len, &modifications, &serverctrls) != SUCCESS) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Osh/|a!", &link, ldap_link_ce, &dn, &dn_len, &modifications, &server_controls_zv) != SUCCESS) {
RETURN_THROWS();
}

Expand Down Expand Up @@ -2636,7 +2636,16 @@ PHP_FUNCTION(ldap_modify_batch)
RETURN_THROWS();
}
} ZEND_HASH_FOREACH_END();
/* validation was successful */
/* validation of modifications array was successful */

/* Check that the LDAP server controls array is valid */
if (server_controls_zv) {
lserverctrls = _php_ldap_controls_from_array(ld->link, server_controls_zv, 4);
if (lserverctrls == NULL) {
_php_ldap_controls_free(&lserverctrls);
RETURN_FALSE;
}
}

/* allocate array of modifications */
uint32_t num_mods = zend_hash_num_elements(modifications);
Expand Down Expand Up @@ -2712,14 +2721,6 @@ PHP_FUNCTION(ldap_modify_batch)
/* NULL-terminate modifications */
ldap_mods[num_mods] = NULL;

if (serverctrls) {
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 4);
if (lserverctrls == NULL) {
RETVAL_FALSE;
goto cleanup;
}
}

/* perform (finally) */
int ldap_status = ldap_modify_ext_s(ld->link, dn, ldap_mods, lserverctrls, NULL);
if (ldap_status != LDAP_SUCCESS) {
Expand Down

0 comments on commit 46a0773

Please sign in to comment.