Skip to content

ext/ldap: php_ldap_do_modify() attempts to free pointer not allocated by ZMM. #16132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Girgias opened this issue Sep 30, 2024 · 0 comments
Closed

Comments

@Girgias
Copy link
Member

Girgias commented Sep 30, 2024

Description

The following code:

<?php

/* ldap_add(_ext)(), ldap_mod_replace(_ext)(), ldap_mod_add(_ext)(), and ldap_mod_del(_ext)() share an underlying C function */
/* We are assuming 3333 is not connectable */
$ldap = ldap_connect('ldap://127.0.0.1:3333');
$valid_dn = "cn=userA,something";

$dict_key_value_not_string = [
    'attribute1' => new stdClass(),
    'attribute2' => [
        'value1',
        'value2',
    ],
];
try {
    var_dump(ldap_add($ldap, $valid_dn, $dict_key_value_not_string));
} catch (Throwable $e) {
    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

Resulted in this output:

php: /home/girgias/Dev/PHP-8.2/Zend/zend_alloc.c:2809: tracked_get_size_zv: Assertion `size_zv && "Trying to free pointer not allocated through ZendMM"' failed.

Termsig=6

But I expected this output instead:

Exception to be caught

Moreover:

The following code:

<?php

/* ldap_add(_ext)(), ldap_mod_replace(_ext)(), ldap_mod_add(_ext)(), and ldap_mod_del(_ext)() share an underlying C function */
/* We are assuming 3333 is not connectable */
$ldap = ldap_connect('ldap://127.0.0.1:3333');
$valid_dn = "cn=userA,something";

$dict_key_multi_value_not_list_of_strings2 = [
    'attribute1' => 'value',
    'attribute2' => [
        'value1',
        new stdClass(),
    ],
];
try {
    var_dump(ldap_add($ldap, $valid_dn, $dict_key_multi_value_not_list_of_strings2));
} catch (Throwable $e) {
    echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

Resulted in this output:

php: /home/girgias/Dev/PHP-8.2/Zend/zend_alloc.c:2809: tracked_get_size_zv: Assertion `size_zv && "Trying to free pointer not allocated through ZendMM"' failed.

Termsig=6

But I expected this output instead:

Exception to be caught

PHP Version

PHP 8.2

Operating System

No response

@Girgias Girgias self-assigned this Sep 30, 2024
Girgias added a commit to Girgias/php-src that referenced this issue Sep 30, 2024
Girgias added a commit that referenced this issue Sep 30, 2024
* PHP-8.2:
  NEWS entries for LDAP bug fixes
  ext/ldap: Fix GH-16136 (Memory leak in php_ldap_do_modify())
  ext/ldap: Fix GH-16132 (Freeing pointer not allocated by ZMM)
Girgias added a commit that referenced this issue Sep 30, 2024
* PHP-8.3:
  NEWS entries for LDAP bug fixes
  ext/ldap: Fix GH-16136 (Memory leak in php_ldap_do_modify())
  ext/ldap: Fix GH-16132 (Freeing pointer not allocated by ZMM)
Girgias added a commit that referenced this issue Sep 30, 2024
* PHP-8.4:
  NEWS entries for LDAP bug fixes
  ext/ldap: Fix GH-16136 (Memory leak in php_ldap_do_modify())
  ext/ldap: Fix GH-16132 (Freeing pointer not allocated by ZMM)
jorgsowa pushed a commit to jorgsowa/php-src that referenced this issue Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant