Skip to content

Commit 459486a

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: ext/ldap: Fix GH-16032 (Various NULL pointer dereferencements in ldap_modify_batch())
2 parents fdd6ba6 + f4c45ee commit 459486a

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Fixed bug GH-16039 (Segmentation fault (access null pointer) in
1111
ext/dom/parentnode/tree.c). (nielsdos)
1212

13+
- LDAP:
14+
. Fixed bug GH-16032 (Various NULL pointer dereferencements in
15+
ldap_modify_batch()). (Girgias)
16+
1317
- PHPDBG:
1418
. Fixed bug GH-15901 (phpdbg: Assertion failure on i funcs). (cmb)
1519

ext/ldap/ldap.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,8 +2618,11 @@ PHP_FUNCTION(ldap_modify_batch)
26182618
/* for the modification hashtable... */
26192619
zend_hash_internal_pointer_reset(Z_ARRVAL_P(mod));
26202620
num_modprops = zend_hash_num_elements(Z_ARRVAL_P(mod));
2621+
bool has_attrib_key = false;
2622+
bool has_modtype_key = false;
26212623

26222624
for (j = 0; j < num_modprops; j++) {
2625+
26232626
/* are the keys strings? */
26242627
if (zend_hash_get_current_key(Z_ARRVAL_P(mod), &modkey, &tmpUlong) != HASH_KEY_IS_STRING) {
26252628
zend_argument_type_error(3, "must only contain string-indexed arrays");
@@ -2641,6 +2644,7 @@ PHP_FUNCTION(ldap_modify_batch)
26412644

26422645
/* does the value type match the key? */
26432646
if (_ldap_str_equal_to_const(ZSTR_VAL(modkey), ZSTR_LEN(modkey), LDAP_MODIFY_BATCH_ATTRIB)) {
2647+
has_attrib_key = true;
26442648
if (Z_TYPE_P(modinfo) != IS_STRING) {
26452649
zend_type_error("%s(): Option \"" LDAP_MODIFY_BATCH_ATTRIB "\" must be of type string, %s given", get_active_function_name(), zend_zval_value_name(modinfo));
26462650
RETURN_THROWS();
@@ -2652,6 +2656,7 @@ PHP_FUNCTION(ldap_modify_batch)
26522656
}
26532657
}
26542658
else if (_ldap_str_equal_to_const(ZSTR_VAL(modkey), ZSTR_LEN(modkey), LDAP_MODIFY_BATCH_MODTYPE)) {
2659+
has_modtype_key = true;
26552660
if (Z_TYPE_P(modinfo) != IS_LONG) {
26562661
zend_type_error("%s(): Option \"" LDAP_MODIFY_BATCH_MODTYPE "\" must be of type int, %s given", get_active_function_name(), zend_zval_value_name(modinfo));
26572662
RETURN_THROWS();
@@ -2715,6 +2720,15 @@ PHP_FUNCTION(ldap_modify_batch)
27152720

27162721
zend_hash_move_forward(Z_ARRVAL_P(mod));
27172722
}
2723+
2724+
if (!has_attrib_key) {
2725+
zend_value_error("%s(): Required option \"" LDAP_MODIFY_BATCH_ATTRIB "\" is missing", get_active_function_name());
2726+
RETURN_THROWS();
2727+
}
2728+
if (!has_modtype_key) {
2729+
zend_value_error("%s(): Required option \"" LDAP_MODIFY_BATCH_MODTYPE "\" is missing", get_active_function_name());
2730+
RETURN_THROWS();
2731+
}
27182732
}
27192733
}
27202734
/* validation was successful */

ext/ldap/tests/gh16032-1.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug GH-16032: Various NULL pointer dereferencements in ldap_modify_batch()
3+
--EXTENSIONS--
4+
ldap
5+
--FILE--
6+
<?php
7+
8+
/* We are assuming 3333 is not connectable */
9+
$ldap = ldap_connect('ldap://127.0.0.1:3333');
10+
$valid_dn = "cn=userA,something";
11+
12+
$modification_missing_attrib_key = [
13+
[
14+
"modtype" => LDAP_MODIFY_BATCH_ADD,
15+
"values" => ["value1"],
16+
],
17+
];
18+
try {
19+
var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_missing_attrib_key));
20+
} catch (Throwable $e) {
21+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
22+
}
23+
24+
?>
25+
--EXPECT--
26+
ValueError: ldap_modify_batch(): Required option "attrib" is missing

ext/ldap/tests/gh16032-2.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug GH-16032: Various NULL pointer dereferencements in ldap_modify_batch()
3+
--EXTENSIONS--
4+
ldap
5+
--FILE--
6+
<?php
7+
8+
/* We are assuming 3333 is not connectable */
9+
$ldap = ldap_connect('ldap://127.0.0.1:3333');
10+
$valid_dn = "cn=userA,something";
11+
12+
$modification_missing_modtype_key = [
13+
[
14+
"attrib" => "attrib1",
15+
"values" => ["value1"],
16+
],
17+
];
18+
try {
19+
var_dump(ldap_modify_batch($ldap, $valid_dn, $modification_missing_modtype_key));
20+
} catch (Throwable $e) {
21+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
22+
}
23+
24+
?>
25+
--EXPECT--
26+
ValueError: ldap_modify_batch(): Required option "modtype" is missing

0 commit comments

Comments
 (0)