Skip to content

Commit 18f61ad

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: ext/ldap: Fix phpGH-16032 (Various NULL pointer dereferencements in ldap_modify_batch())
2 parents 4b8a12d + 459486a commit 18f61ad

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
@@ -11,6 +11,10 @@ PHP NEWS
1111
. Fixed bug GH-16039 (Segmentation fault (access null pointer) in
1212
ext/dom/parentnode/tree.c). (nielsdos)
1313

14+
- LDAP:
15+
. Fixed bug GH-16032 (Various NULL pointer dereferencements in
16+
ldap_modify_batch()). (Girgias)
17+
1418
- Opcache:
1519
. Fixed bug GH-16009 (Segmentation fault with frameless functions and
1620
undefined CVs). (nielsdos)

ext/ldap/ldap.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,8 +2620,11 @@ PHP_FUNCTION(ldap_modify_batch)
26202620
/* for the modification hashtable... */
26212621
zend_hash_internal_pointer_reset(Z_ARRVAL_P(mod));
26222622
num_modprops = zend_hash_num_elements(Z_ARRVAL_P(mod));
2623+
bool has_attrib_key = false;
2624+
bool has_modtype_key = false;
26232625

26242626
for (j = 0; j < num_modprops; j++) {
2627+
26252628
/* are the keys strings? */
26262629
if (zend_hash_get_current_key(Z_ARRVAL_P(mod), &modkey, &tmpUlong) != HASH_KEY_IS_STRING) {
26272630
zend_argument_type_error(3, "must only contain string-indexed arrays");
@@ -2643,6 +2646,7 @@ PHP_FUNCTION(ldap_modify_batch)
26432646

26442647
/* does the value type match the key? */
26452648
if (_ldap_str_equal_to_const(ZSTR_VAL(modkey), ZSTR_LEN(modkey), LDAP_MODIFY_BATCH_ATTRIB)) {
2649+
has_attrib_key = true;
26462650
if (Z_TYPE_P(modinfo) != IS_STRING) {
26472651
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));
26482652
RETURN_THROWS();
@@ -2654,6 +2658,7 @@ PHP_FUNCTION(ldap_modify_batch)
26542658
}
26552659
}
26562660
else if (_ldap_str_equal_to_const(ZSTR_VAL(modkey), ZSTR_LEN(modkey), LDAP_MODIFY_BATCH_MODTYPE)) {
2661+
has_modtype_key = true;
26572662
if (Z_TYPE_P(modinfo) != IS_LONG) {
26582663
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));
26592664
RETURN_THROWS();
@@ -2717,6 +2722,15 @@ PHP_FUNCTION(ldap_modify_batch)
27172722

27182723
zend_hash_move_forward(Z_ARRVAL_P(mod));
27192724
}
2725+
2726+
if (!has_attrib_key) {
2727+
zend_value_error("%s(): Required option \"" LDAP_MODIFY_BATCH_ATTRIB "\" is missing", get_active_function_name());
2728+
RETURN_THROWS();
2729+
}
2730+
if (!has_modtype_key) {
2731+
zend_value_error("%s(): Required option \"" LDAP_MODIFY_BATCH_MODTYPE "\" is missing", get_active_function_name());
2732+
RETURN_THROWS();
2733+
}
27202734
}
27212735
}
27222736
/* 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)