-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix ldap memory bugs for PHP 7.3 (fix: #79773) #5799
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
Conversation
3bb7632
to
3cd005c
Compare
3cd005c
to
dda79dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks right to me, just some style nits.
@@ -397,7 +398,6 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra | |||
if (ber_flatten2(vrber, control_value, 0) == -1) { | |||
rc = -1; | |||
} | |||
ber_free(vrber, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely glossed over this line before ... this doesn't look right to me. Why does removing this not cause a memory leak? I don't see anything else that would free vrber.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somehow this caused a "Protocol error" which appeared to be a bad memory access (access to freed memory). I guess, this is specific to how the ber_flatten2()
is implemented. If the third argument called alloc
is zero, then it just assigns vrber->ber_buf
to control_value->bv_val
without allocating memory for control_value
. The memory is released later with ber_memfree(control_value)
at line 618. From what I've seen, this is recurring pattern in ldap.c
- I couldn't find other pieces of code with ber_free()
following ber_flatten2()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, that makes sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... just got back to this, and it looks like I could be wrong. The memory allocated for vrber->ber_buf
is probably freed with ber_memfree(control_value)
, but there is still memory allocated for vrber
itself. So removing completely this line was wrong. My bad. Perhaps we should replace it with ber_free(vrber, 0)
, or move the ber_free(vrber, 1)
near the end of the function.
I've merged the use-after-free / memory-leak fixes into 7.3 as 23ef0a1. I'm going to apply the CI changes for 7.4 upwards. |
This PR enables
ext/ldap/tests
on travis and fixes some ldap memory bugs as described in #79773.