-
Notifications
You must be signed in to change notification settings - Fork 135
Fix(LDAPObject): Prevent search attrlist memory error #555
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
base: main
Are you sure you want to change the base?
Fix(LDAPObject): Prevent search attrlist memory error #555
Conversation
tiran
left a comment
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.
Excellent finding. Thanks for the bug report and patch with tests. Much appreciated.
I suggest a slightly different fix to align the change with other upcoming changes.
droideck
left a comment
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.
LGTM!
d1358f6 to
0859ed8
Compare
|
Sorry, lost track of this for a bit. I squashed the commits and adjusted the commit message. |
|
@jkoeniger I think it should be good to merge. Could you please rebase it? |
|
@droideck @jkoeniger is in vacation for the next two weeks. |
|
@tiran needs to unset the |
be2210b to
1e46c73
Compare
|
@droideck Rebase done. Can be merged. |
Add tests test_valid_attrlist_parameter_types and test_invalid_attrlist_parameter_types which test the behaviour when passing different Python types. All iterables which return only strings should pass, everything else should raise a TypeError.
Function `PySequence_Length` can return -1 on iterables like `dict`. The following PyMem_NEW still succeeds due `PyMem_NEW(char *, -1 + 1)` being equivalent to `char** PyMem_Malloc(1)`, which then can result in a segmentation fault later on. Solution: Use `seq` and `PySequence_Size` to determine the size of the sequence. This way any iterable which contains only strings can be used. Co-authored-by: Christian Heimes <christian@python.org>
1e46c73 to
450842d
Compare
Problem
Providing a dictionary to
attrlist(LDAPObject.search_ext) results in a memory error.See Issue #556
Root cause
Function
PySequence_Lengthcan 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
TypeErroror 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
TypeErrorin 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
seqandPySequence_Fast_GET_SIZEto 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.