Skip to content

ext/ldap: fix leak on port overflow check. #18645

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

Open
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from

Conversation

devnexen
Copy link
Member

No description provided.

ext/ldap/ldap.c Outdated
@@ -994,6 +994,7 @@ PHP_FUNCTION(ldap_connect)
size_t urllen = hostlen + sizeof( "ldap://:65535" );

if (port <= 0 || port > 65535) {
zval_ptr_dtor(return_value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't "clear out" the return value, so you'll get a double free later I think.
Instead, the proper fix is probably moving the object_init_ex and assignment to ld further down (and then getting rid of the existing zval_ptr_dtor(return_value); under #ifdef LDAP_OPT_X_TLS_NEWCTX

@nielsdos
Copy link
Member

Can you try to minimize the diff by not re-indenting?

@devnexen devnexen force-pushed the ldap_check_leaks branch 2 times, most recently from 657f79b to 890c2f0 Compare May 24, 2025 21:44
@nielsdos
Copy link
Member

Don't forget to remove that now-redundant zval_ptr_dtor(return_value); at now-line 1009

@devnexen devnexen force-pushed the ldap_check_leaks branch from 890c2f0 to df91d36 Compare May 24, 2025 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants