From: Douglas Bagnall Date: Thu, 14 Mar 2024 23:38:00 +0000 (+1300) Subject: pyldb: make py_ldb_dn_add_base() a bit less leaky X-Git-Tag: tdb-1.4.11~1207 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f8b92e52811a87193ed326a97ff8ac2f440dcf7b;p=thirdparty%2Fsamba.git pyldb: make py_ldb_dn_add_base() a bit less leaky Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index 3786ca284a7..18613f59f2f 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -697,25 +697,43 @@ static PyObject *py_ldb_dn_add_child(PyObject *self, PyObject *args) static PyObject *py_ldb_dn_add_base(PyObject *self, PyObject *args) { - PyObject *py_other; + PyObject *py_other = NULL; struct ldb_dn *other = NULL; struct ldb_dn *dn = NULL; + TALLOC_CTX *tmp_ctx = NULL; bool ok; PyErr_LDB_DN_OR_RAISE(self, dn); - if (!PyArg_ParseTuple(args, "O", &py_other)) + if (!PyArg_ParseTuple(args, "O", &py_other)) { return NULL; + } - if (!pyldb_Object_AsDn(NULL, py_other, ldb_dn_get_ldb_context(dn), &other)) + /* + * As noted in py_ldb_dn_add_child() comments, if py_other is a + * string, other is an ephemeral struct ldb_dn, but if py_other is a + * python DN, other points to the corresponding long-lived DN. + */ + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + PyErr_NoMemory(); + return NULL; + } + ok = pyldb_Object_AsDn(tmp_ctx, + py_other, + ldb_dn_get_ldb_context(dn), + &other); + if (!ok) { + TALLOC_FREE(tmp_ctx); return NULL; + } ok = ldb_dn_add_base(dn, other); + TALLOC_FREE(tmp_ctx); if (!ok) { PyErr_SetLdbError(PyExc_LdbError, LDB_ERR_OPERATIONS_ERROR, NULL); return NULL; } - Py_RETURN_TRUE; }