Skip to content

Commit e18c567

Browse files
committed
fix(LDAPObject): Prevent memory errors in attrs_from_List
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_Fast_GET_SIZE` to determine the size of the sequence. This way any iterable which contains only strings can be used.
1 parent a1bdf47 commit e18c567

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Modules/LDAPObject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ attrs_from_List(PyObject *attrlist, char ***attrsp)
288288
if (seq == NULL)
289289
goto error;
290290

291-
len = PySequence_Length(attrlist);
291+
len = PySequence_Fast_GET_SIZE(seq);
292292

293293
attrs = PyMem_NEW(char *, len + 1);
294294

0 commit comments

Comments
 (0)