-
Notifications
You must be signed in to change notification settings - Fork 127
Closed
Description
The function
python-ldap/Modules/LDAPObject.c
Line 251 in 084ffe0
attrs_from_List( PyObject *attrlist, char***attrsp, PyObject** seq) { |
char *
. It allocates memory for the array itself but uses PyUnicode_AsUTF8
or PyBytes_AsString
for the elements inside the array. Both functions do not return a copy of the string but rather a reference to an internal buffer. The internal buffer is shared between callers and must be treated as const, immutable block. In fact in Python 3.7+, the return value of PyUnicode_AsUTF8
has been changed to const char*
, https://docs.python.org/3.7/c-api/unicode.html#c.PyUnicode_AsUTF8AndSize . However ldap_search_ext
does not take a const char*[]
but a char *attrs[]
. This breaks the const promise starting with Python 3.7.
Even more peculiar is the seq
argument. It is used to pass back a reference to the Python sequence that holds the PyObject *
. This trick is used to keep the Python sequence and all its members alive, so the elements in the array of char *
do not get deallocated by Python.
I suggest to change the function to copy the strings to allocated buffers instead of (ab)using Python objects to provide the buffer. The performance impact of additional PyMem_NEW
and memcpy
is negligible.
Metadata
Metadata
Assignees
Labels
No labels