Skip to content

Commit 77e934e

Browse files
tiranencukou
authored andcommitted
Fix ref counting bug in LDAPmessage_to_python
PyDict_GetItem() returns a borrowed reference. The code later Py_DECREF() the reference, which causes a segfault at a later point in time. Fixes: #218 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 68a6db6 commit 77e934e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Modules/message.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,15 @@ LDAPmessage_to_python(LDAP *ld, LDAPMessage *m, int add_ctrls,
9999

100100
/* Find which list to append to */
101101
if (PyDict_Contains(attrdict, pyattr)) {
102+
/* Multiple attribute entries with same name. This code path
103+
* is rarely used and cannot be exhausted with OpenLDAP
104+
* tests. 389-DS sometimes triggeres it, see
105+
* https://github.com/python-ldap/python-ldap/issues/218
106+
*/
102107
valuelist = PyDict_GetItem(attrdict, pyattr);
108+
/* Turn borrowed reference into owned reference */
109+
if (valuelist != NULL)
110+
Py_INCREF(valuelist);
103111
}
104112
else {
105113
valuelist = PyList_New(0);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy