From 474674ac7db997f678394d054f64a1d560f6b020 Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Tue, 17 Jan 2023 12:33:17 +1300 Subject: [PATCH] lib:pyldb: Throw error on invalid controls Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- lib/ldb/pyldb.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index 7a95a58fa67..da60572ff0f 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -1291,6 +1291,11 @@ static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args, PyObject *kwar return NULL; } parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls); + if (controls[0] != NULL && parsed_controls == NULL) { + talloc_free(mem_ctx); + PyErr_SetLdbError(PyExc_LdbError, LDB_ERR_OPERATIONS_ERROR, ldb_ctx); + return NULL; + } talloc_free(controls); } @@ -1440,6 +1445,11 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args, PyObject *kwargs) return NULL; } parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls); + if (controls[0] != NULL && parsed_controls == NULL) { + talloc_free(mem_ctx); + PyErr_SetLdbError(PyExc_LdbError, LDB_ERR_OPERATIONS_ERROR, ldb_ctx); + return NULL; + } talloc_free(controls); } @@ -1533,6 +1543,11 @@ static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args, PyObject *kwar return NULL; } parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls); + if (controls[0] != NULL && parsed_controls == NULL) { + talloc_free(mem_ctx); + PyErr_SetLdbError(PyExc_LdbError, LDB_ERR_OPERATIONS_ERROR, ldb_ctx); + return NULL; + } talloc_free(controls); } @@ -1611,6 +1626,11 @@ static PyObject *py_ldb_rename(PyLdbObject *self, PyObject *args, PyObject *kwar return NULL; } parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls); + if (controls[0] != NULL && parsed_controls == NULL) { + talloc_free(mem_ctx); + PyErr_SetLdbError(PyExc_LdbError, LDB_ERR_OPERATIONS_ERROR, ldb_ctx); + return NULL; + } talloc_free(controls); } @@ -1973,6 +1993,11 @@ static PyObject *py_ldb_search(PyLdbObject *self, PyObject *args, PyObject *kwar return NULL; } parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls); + if (controls[0] != NULL && parsed_controls == NULL) { + talloc_free(mem_ctx); + PyErr_SetLdbError(PyExc_LdbError, LDB_ERR_OPERATIONS_ERROR, ldb_ctx); + return NULL; + } talloc_free(controls); } @@ -2179,7 +2204,7 @@ static PyObject *py_ldb_search_iterator(PyLdbObject *self, PyObject *args, PyObj controls); if (controls[0] != NULL && parsed_controls == NULL) { Py_DECREF(py_iter); - PyErr_NoMemory(); + PyErr_SetLdbError(PyExc_LdbError, LDB_ERR_OPERATIONS_ERROR, ldb_ctx); return NULL; } talloc_free(controls);