]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pyldb: Fix Message.items() for a message containing elements
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Fri, 28 May 2021 02:15:43 +0000 (14:15 +1200)
committerStefan Metzmacher <metze@samba.org>
Tue, 2 Nov 2021 21:52:16 +0000 (21:52 +0000)
Previously, message elements were being freed before the call to
Py_BuildValue(), resulting in an exception being raised. Additionally,
only the first element of the returned list was ever assigned to.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
(cherry picked from commit 3e4ec0a90a222c1cff4a91912afc703ca4cbbb0e)

lib/ldb/pyldb.c

index 257351b2bc454d9f172eb58e6820a753668e76ac..df7c5c54eaaa5a6bb7c8df425ff0d2ebd512c330 100644 (file)
@@ -3535,13 +3535,13 @@ static PyObject *py_ldb_msg_items(PyLdbMessageObject *self,
                PyObject *value = NULL;
                PyObject *py_el = PyLdbMessageElement_FromMessageElement(&msg->elements[i], msg->elements);
                int res = 0;
-               Py_CLEAR(py_el);
                value = Py_BuildValue("(sO)", msg->elements[i].name, py_el);
+               Py_CLEAR(py_el);
                if (value == NULL ) {
                        Py_CLEAR(l);
                        return NULL;
                }
-               res = PyList_SetItem(l, 0, value);
+               res = PyList_SetItem(l, j, value);
                if (res == -1) {
                        Py_CLEAR(l);
                        return NULL;