Skip to content

Commit 72a4707

Browse files
authored
Fix NULL deref and checks in LDAPmessage_to_python
The function LDAPmessage_to_python() had some potential NULL pointer derefs and missed a couple of errors checks. It's still not perfect but a bit better now. python-ldap#342 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 9a91bbd commit 72a4707

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

Modules/message.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,35 @@ LDAPmessage_to_python(LDAP *ld, LDAPMessage *m, int add_ctrls,
273273

274274
valuestr = LDAPberval_to_object(retdata);
275275
ber_bvfree(retdata);
276+
if (valuestr == NULL) {
277+
ldap_memfree(retoid);
278+
Py_DECREF(result);
279+
ldap_msgfree(m);
280+
return NULL;
281+
}
282+
276283
pyoid = PyUnicode_FromString(retoid);
277284
ldap_memfree(retoid);
278285
if (pyoid == NULL) {
286+
Py_DECREF(valuestr);
287+
Py_DECREF(result);
288+
ldap_msgfree(m);
289+
return NULL;
290+
}
291+
292+
valtuple = Py_BuildValue("(NNN)", pyoid, valuestr, pyctrls);
293+
if (valtuple == NULL) {
294+
Py_DECREF(result);
295+
ldap_msgfree(m);
296+
return NULL;
297+
}
298+
299+
if (PyList_Append(result, valtuple) == -1) {
300+
Py_DECREF(valtuple);
279301
Py_DECREF(result);
280302
ldap_msgfree(m);
281303
return NULL;
282304
}
283-
valtuple = Py_BuildValue("(OOO)", pyoid,
284-
valuestr ? valuestr : Py_None,
285-
pyctrls);
286-
Py_DECREF(pyoid);
287-
Py_DECREF(valuestr);
288-
Py_XDECREF(pyctrls);
289-
PyList_Append(result, valtuple);
290305
Py_DECREF(valtuple);
291306
}
292307
}

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