diff options
author | Noel Power <noel.power@suse.com> | 2019-01-25 12:02:50 +0000 |
---|---|---|
committer | Noel Power <npower@samba.org> | 2019-02-07 13:44:30 +0100 |
commit | 1be9b0cf1bc95715e83c27eabecbd4fa2022530b (patch) | |
tree | 9b6e79e6cccc69d788f12e8ae7f833cecd4693a3 | |
parent | a8e10a12493fdb6b8347b14e157aeb619cf2d2da (diff) | |
download | samba-1be9b0cf1bc95715e83c27eabecbd4fa2022530b.tar.gz |
Examine result of SetList (and prevent sending NULL to PyList_SetItem)
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
-rw-r--r-- | lib/ldb/pyldb.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index a4618db8d35..1d4fe59f103 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -3430,17 +3430,41 @@ static PyObject *py_ldb_msg_items(PyLdbMessageObject *self) struct ldb_message *msg = pyldb_Message_AsMessage(self); Py_ssize_t i, j = 0; PyObject *l = PyList_New(msg->num_elements + (msg->dn == NULL?0:1)); + if (l == NULL) { + return PyErr_NoMemory(); + } if (msg->dn != NULL) { + PyObject *value = NULL; PyObject *obj = pyldb_Dn_FromDn(msg->dn); - PyList_SetItem(l, 0, Py_BuildValue("(sO)", "dn", obj)); + int res = 0; + value = Py_BuildValue("(sO)", "dn", obj); Py_CLEAR(obj); + if (value == NULL) { + Py_CLEAR(l); + return NULL; + } + res = PyList_SetItem(l, 0, value); + if (res == -1) { + Py_CLEAR(l); + return NULL; + } j++; } for (i = 0; i < msg->num_elements; i++, j++) { + PyObject *value = NULL; PyObject *py_el = PyLdbMessageElement_FromMessageElement(&msg->elements[i], msg->elements); - PyObject *value = Py_BuildValue("(sO)", msg->elements[i].name, py_el); + int res = 0; Py_CLEAR(py_el); - PyList_SetItem(l, j, value); + value = Py_BuildValue("(sO)", msg->elements[i].name, py_el); + if (value == NULL ) { + Py_CLEAR(l); + return NULL; + } + res = PyList_SetItem(l, 0, value); + if (res == -1) { + Py_CLEAR(l); + return NULL; + } } return l; } |