pyldb: ldb.register_module() checks arguments a little bit
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 4 Jul 2019 04:43:12 +0000 (16:43 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Wed, 10 Jul 2019 04:32:13 +0000 (04:32 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
lib/ldb/pyldb.c
selftest/knownfail.d/python-segfaults

index 13d7c962d1e48c873a516631768e531d54433945..a6069be46a9257bb34276d283e4680ddfe9b568e 100644 (file)
@@ -4136,7 +4136,8 @@ static PyObject *py_register_module(PyObject *module, PyObject *args)
        int ret;
        struct ldb_module_ops *ops;
        PyObject *input;
-       PyObject *tmp;
+       PyObject *tmp = NULL;
+       const char *name = NULL;
 
        if (!PyArg_ParseTuple(args, "O", &input))
                return NULL;
@@ -4148,10 +4149,17 @@ static PyObject *py_register_module(PyObject *module, PyObject *args)
        }
 
        tmp = PyObject_GetAttrString(input, discard_const_p(char, "name"));
-       ops->name = talloc_strdup(ops, PyUnicode_AsUTF8(tmp));
-
+       if (tmp == NULL) {
+               return NULL;
+       }
+       name = PyUnicode_AsUTF8(tmp);
+       if (name == NULL) {
+               return NULL;
+       }
        Py_XDECREF(tmp);
        Py_INCREF(input);
+
+       ops->name = talloc_strdup(ops, name);
        ops->private_data = input;
        ops->init_context = py_module_init;
        ops->search = py_module_search;
index e5821538b6ed3df1d3fb0cc74d10f2524565eda7..42f83f8b8b9c6cf729a54736d9baa72b469c06ea 100644 (file)
@@ -1,5 +1,4 @@
 samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_encrypt_netr_crypt_password
 samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_hive_open_ldb
-samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_ldb_register_module
 samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_net_replicate_chunk_1
 samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_net_replicate_init__3