pyldb: Report errors converting controls list to char**
authorPetr Viktorin <pviktori@redhat.com>
Tue, 3 Mar 2015 21:29:13 +0000 (22:29 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 3 Mar 2015 22:20:06 +0000 (23:20 +0100)
With this change, passing an unexpected type to the CRUD methods
will result in an informative TypeError.

Signed-off-by: Petr Viktorin <pviktori@redhat.com>
Reviewed-by: Jelmer Vernooij <jelmer@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/pyldb.c

index a3ffde92c6415196fca900e0e6a66389a615d758..f18e06e5c686512a03c1a7b8ff7ea7fcaba64efa 100644 (file)
@@ -1109,6 +1109,10 @@ static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args, PyObject *kwar
                parsed_controls = NULL;
        } else {
                const char **controls = PyList_AsStringList(mem_ctx, py_controls, "controls");
+               if (controls == NULL) {
+                       talloc_free(mem_ctx);
+                       return NULL;
+               }
                parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls);
                talloc_free(controls);
        }
@@ -1254,6 +1258,10 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args, PyObject *kwargs)
                parsed_controls = NULL;
        } else {
                const char **controls = PyList_AsStringList(mem_ctx, py_controls, "controls");
+               if (controls == NULL) {
+                       talloc_free(mem_ctx);
+                       return NULL;
+               }
                parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls);
                talloc_free(controls);
        }
@@ -1343,6 +1351,10 @@ static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args, PyObject *kwar
                parsed_controls = NULL;
        } else {
                const char **controls = PyList_AsStringList(mem_ctx, py_controls, "controls");
+               if (controls == NULL) {
+                       talloc_free(mem_ctx);
+                       return NULL;
+               }
                parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls);
                talloc_free(controls);
        }
@@ -1417,6 +1429,10 @@ static PyObject *py_ldb_rename(PyLdbObject *self, PyObject *args, PyObject *kwar
                parsed_controls = NULL;
        } else {
                const char **controls = PyList_AsStringList(mem_ctx, py_controls, "controls");
+               if (controls == NULL) {
+                       talloc_free(mem_ctx);
+                       return NULL;
+               }
                parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls);
                talloc_free(controls);
        }
@@ -1717,6 +1733,10 @@ static PyObject *py_ldb_search(PyLdbObject *self, PyObject *args, PyObject *kwar
                parsed_controls = NULL;
        } else {
                const char **controls = PyList_AsStringList(mem_ctx, py_controls, "controls");
+               if (controls == NULL) {
+                       talloc_free(mem_ctx);
+                       return NULL;
+               }
                parsed_controls = ldb_parse_control_strings(ldb_ctx, mem_ctx, controls);
                talloc_free(controls);
        }