pyldb: don't allow py_ldb_dn_copy() with the wrong pyldb
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sun, 17 Mar 2024 23:24:53 +0000 (12:24 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 10 Apr 2024 05:13:32 +0000 (05:13 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/pyldb.c

index 081501da40d0f510575bd353db852493600a5283..f416bfe6d5d70551f1c3d04c4abc4e8e398e9429 100644 (file)
@@ -1077,6 +1077,19 @@ static PyObject *py_ldb_dn_copy(struct ldb_dn *dn, PyLdbObject *pyldb)
        struct ldb_dn *new_dn = NULL;
        PyLdbDnObject *py_ret;
 
+       if (ldb_dn_get_ldb_context(dn) != pyldb->ldb_ctx) {
+               /*
+                * We can't do this, because we can't (for now) change the ldb
+                * pointer of the underlying dn returned by ldb_dn_copy().
+                *
+                * This error means someone editing this file got confused,
+                * which is quite understandable.
+                */
+               PyErr_SetString(PyExc_RuntimeError,
+                               "py_ldb_dn_copy can't copy to a new LDB");
+               return NULL;
+       }
+
        mem_ctx = talloc_new(NULL);
        if (mem_ctx == NULL) {
                return PyErr_NoMemory();