Skip to content

Commit

Permalink
Fix NULL deref and checks in LDAPmessage_to_python
Browse files Browse the repository at this point in the history
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.

https://github.com/python-ldap/python-ldap/pull/342

Signed-off-by: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
Christian Heimes authored and GitHub committed Jun 5, 2020
1 parent 9a91bbd commit 72a4707
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions Modules/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,35 @@ LDAPmessage_to_python(LDAP *ld, LDAPMessage *m, int add_ctrls,

valuestr = LDAPberval_to_object(retdata);
ber_bvfree(retdata);
if (valuestr == NULL) {
ldap_memfree(retoid);
Py_DECREF(result);
ldap_msgfree(m);
return NULL;
}

pyoid = PyUnicode_FromString(retoid);
ldap_memfree(retoid);
if (pyoid == NULL) {
Py_DECREF(valuestr);
Py_DECREF(result);
ldap_msgfree(m);
return NULL;
}

valtuple = Py_BuildValue("(NNN)", pyoid, valuestr, pyctrls);
if (valtuple == NULL) {
Py_DECREF(result);
ldap_msgfree(m);
return NULL;
}

if (PyList_Append(result, valtuple) == -1) {
Py_DECREF(valtuple);
Py_DECREF(result);
ldap_msgfree(m);
return NULL;
}
valtuple = Py_BuildValue("(OOO)", pyoid,
valuestr ? valuestr : Py_None,
pyctrls);
Py_DECREF(pyoid);
Py_DECREF(valuestr);
Py_XDECREF(pyctrls);
PyList_Append(result, valtuple);
Py_DECREF(valtuple);
}
}
Expand Down

0 comments on commit 72a4707

Please sign in to comment.