Skip to content

Commit

Permalink
Fix ref counting bug in LDAPmessage_to_python
Browse files Browse the repository at this point in the history
PyDict_GetItem() returns a borrowed reference. The code later
Py_DECREF() the reference, which causes a segfault at a later point in
time.

Fixes: https://github.com/python-ldap/python-ldap/issues/218
Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes authored and Petr Viktorin committed May 25, 2018
1 parent 68a6db6 commit 77e934e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Modules/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ LDAPmessage_to_python(LDAP *ld, LDAPMessage *m, int add_ctrls,

/* Find which list to append to */
if (PyDict_Contains(attrdict, pyattr)) {
/* Multiple attribute entries with same name. This code path
* is rarely used and cannot be exhausted with OpenLDAP
* tests. 389-DS sometimes triggeres it, see
* https://github.com/python-ldap/python-ldap/issues/218
*/
valuelist = PyDict_GetItem(attrdict, pyattr);
/* Turn borrowed reference into owned reference */
if (valuelist != NULL)
Py_INCREF(valuelist);
}
else {
valuelist = PyList_New(0);
Expand Down

0 comments on commit 77e934e

Please sign in to comment.