ldb: Check talloc_strdup() return value
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Mon, 31 Jul 2023 21:48:35 +0000 (09:48 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 8 Aug 2023 04:39:37 +0000 (04:39 +0000)
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/pyldb.c

index 8db6ccb8bc10f05fcd99dbb78ce5a803756f63b3..cc222ed7f3d64bc1e8a301dd390c87753e9858ef 100644 (file)
@@ -3165,6 +3165,11 @@ static struct ldb_message_element *PyObject_AsMessageElement(
        }
 
        me->name = talloc_strdup(me, attr_name);
+       if (me->name == NULL) {
+               PyErr_NoMemory();
+               talloc_free(me);
+               return NULL;
+       }
        me->flags = flags;
        if (PyBytes_Check(set_obj) || PyUnicode_Check(set_obj)) {
                me->num_values = 1;
@@ -3442,6 +3447,10 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb
        el->flags = flags;
        if (name != NULL) {
                el->name = talloc_strdup(el, name);
+               if (el->name == NULL) {
+                       talloc_free(mem_ctx);
+                       return PyErr_NoMemory();
+               }
        }
 
        ret = PyObject_New(PyLdbMessageElementObject, type);
@@ -4363,10 +4372,14 @@ static PyObject *py_register_module(PyObject *module, PyObject *args)
                TALLOC_FREE(ops);
                return NULL;
        }
-       Py_INCREF(input);
 
        ops->name = talloc_strdup(ops, name);
        Py_XDECREF(tmp);
+       if (ops->name == NULL) {
+               TALLOC_FREE(ops);
+               return PyErr_NoMemory();
+       }
+       Py_INCREF(input);
        ops->private_data = input;
        ops->init_context = py_module_init;
        ops->search = py_module_search;