Fix(LDAPObject): Prevent search attrlist memory error #555
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.
Problem
Providing a dictionary to
attrlist
(LDAPObject.search_ext) results in a memory error.See Issue #556
Root cause
Function
PySequence_Length
can return -1 on iterables likedict
. The following PyMem_NEW still succeeds duePyMem_NEW(char *, -1 + 1)
being equivalent tochar** PyMem_Malloc(1)
, which then can result in asegmentation fault later on.
Solution
The expected behavior should be either a raised
TypeError
or that any iterable which contains only strings can be passed.Commit e18c567 enables the latter which is in itself very unlikely to break anything. I would actually prefer to raise a
TypeError
in the C extension on encountering a dictionary as it is most likely an error on the callers side, maybe we can add that later.The fix in e18c567 is to use
seq
andPySequence_Fast_GET_SIZE
to determine the size of the sequence. This way any iterable which contains only strings can be used. I added two tests in a1bdf47 which will fail without the fix in e18c567.