xref: /php-src/ext/ldap/tests/gh16136.phpt (revision d34d0150)
1--TEST--
2Bug GH-16136: Memory leak in php_ldap_do_modify() when entry is not a proper dictionary
3--EXTENSIONS--
4ldap
5--FILE--
6<?php
7
8/* ldap_add(_ext)(), ldap_mod_replace(_ext)(), ldap_mod_add(_ext)(), and ldap_mod_del(_ext)() share an underlying C function */
9/* We are assuming 3333 is not connectable */
10$ldap = ldap_connect('ldap://127.0.0.1:3333');
11$valid_dn = "cn=userA,something";
12
13$not_dict_of_attributes = [
14    'attribute1' => 'value',
15    'not_key_entry',
16    'attribute3' => [
17        'value1',
18        'value2',
19    ],
20];
21try {
22    var_dump(ldap_add($ldap, $valid_dn, $not_dict_of_attributes));
23} catch (Throwable $e) {
24    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
25}
26
27?>
28--EXPECT--
29ValueError: ldap_add(): Argument #3 ($entry) must be an associative array of attribute => values
30