fix(message): prevent segfault on invalid UTF-8 - #624
Merged
Merged
Conversation
Check `PyUnicode_FromString()` results for attribute names and referrals to avoid NULL pointer dereferences.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During fuzzing, two segfaults were found in
LDAPmessage_to_python()due to unchecked failures fromPyUnicode_FromString(). Other uses ofPyUnicode_FromString()in this function already check forNULLbefore using the returned object. Valgrind logs were captured against python-ldap 3.4.5. The currentmainbranch exhibits the same crash behavior.Although such malformed UTF-8 is not expected from a compliant LDAP server, untrusted server input should not be able to crash the Python interpreter.
1. PyDict_Contains
LDAPmessage_to_python()did not check the return value ofPyUnicode_FromString(attr). Invalid UTF-8 in an attribute name therefore resulted in a NULL pointer being passed toPyDict_Contains(), crashing the interpreter.A part of valgrind log:
2. Py_DECREF
LDAPmessage_to_python()did not check the return value ofPyUnicode_FromString()for referral URLs. Invalid UTF-8 therefore leftrefstr == NULL; after the ignoredPyList_Append()failure,Py_DECREF(refstr)crashed the interpreter.A part of valgrind log:
Reproduction script