Skip to content

Commit b0f639d

Browse files
committed
ext/ldap: Move server controls check prior to allocating modifications
1 parent 7bab815 commit b0f639d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

ext/ldap/ldap.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,7 +2494,7 @@ PHP_FUNCTION(ldap_delete_ext)
24942494
/* {{{ Perform multiple modifications as part of one operation */
24952495
PHP_FUNCTION(ldap_modify_batch)
24962496
{
2497-
zval *serverctrls = NULL;
2497+
zval *server_controls_zv = NULL;
24982498
ldap_linkdata *ld;
24992499
zval *link;
25002500
char *dn;
@@ -2527,7 +2527,7 @@ PHP_FUNCTION(ldap_modify_batch)
25272527
];
25282528
*/
25292529

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

@@ -2638,7 +2638,15 @@ PHP_FUNCTION(ldap_modify_batch)
26382638
RETURN_THROWS();
26392639
}
26402640
} ZEND_HASH_FOREACH_END();
2641-
/* validation was successful */
2641+
/* validation of modifications array was successful */
2642+
2643+
/* Check that the LDAP server controls array is valid */
2644+
if (server_controls_zv) {
2645+
lserverctrls = _php_ldap_controls_from_array(ld->link, server_controls_zv, 4);
2646+
if (lserverctrls == NULL) {
2647+
RETURN_FALSE;
2648+
}
2649+
}
26422650

26432651
/* allocate array of modifications */
26442652
uint32_t num_mods = zend_hash_num_elements(modifications);
@@ -2714,14 +2722,6 @@ PHP_FUNCTION(ldap_modify_batch)
27142722
/* NULL-terminate modifications */
27152723
ldap_mods[num_mods] = NULL;
27162724

2717-
if (serverctrls) {
2718-
lserverctrls = _php_ldap_controls_from_array(ld->link, serverctrls, 4);
2719-
if (lserverctrls == NULL) {
2720-
RETVAL_FALSE;
2721-
goto cleanup;
2722-
}
2723-
}
2724-
27252725
/* perform (finally) */
27262726
int ldap_status = ldap_modify_ext_s(ld->link, dn, ldap_mods, lserverctrls, NULL);
27272727
if (ldap_status != LDAP_SUCCESS) {

0 commit comments

Comments
 (0)