From: Douglas Bagnall Date: Wed, 2 May 2018 23:17:55 +0000 (+1200) Subject: pyldb: check for errors in PyLdb_GetPyType() X-Git-Tag: talloc-2.3.0~126 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=339f8bbdda04a23460e7fa908d60857b95271c6e;p=thirdparty%2Fsamba.git pyldb: check for errors in PyLdb_GetPyType() Signed-off-by: Douglas Bagnall Reviewed-by: Gary Lockyer --- diff --git a/lib/ldb/pyldb_util.c b/lib/ldb/pyldb_util.c index a1e3233e6ba..811511547ed 100644 --- a/lib/ldb/pyldb_util.c +++ b/lib/ldb/pyldb_util.c @@ -34,7 +34,8 @@ static PyObject *ldb_module = NULL; */ static PyTypeObject * PyLdb_GetPyType(const char *typename) { - PyObject *py_obj = NULL; + PyTypeObject *type = NULL; + bool ok; if (ldb_module == NULL) { ldb_module = PyImport_ImportModule("ldb"); @@ -43,9 +44,26 @@ static PyTypeObject * PyLdb_GetPyType(const char *typename) } } - py_obj = PyObject_GetAttrString(ldb_module, typename); + type = (PyTypeObject *)PyObject_GetAttrString(ldb_module, typename); - return (PyTypeObject*)py_obj; + + if (type == NULL) { + PyErr_Format(PyExc_NameError, + "Unable to find type %s in ldb module", + typename); + return NULL; + } + + ok = PyType_Check(type); + if (! ok) { + PyErr_Format(PyExc_TypeError, + "Expected type ldb.%s, not %s", + typename, Py_TYPE(type)->tp_name); + Py_DECREF(type); + return NULL; + } + + return type; } bool pyldb_check_type(PyObject *obj, const char *typename) diff --git a/selftest/knownfail.d/python-segfaults b/selftest/knownfail.d/python-segfaults index c8331d941ef..42f83f8b8b9 100644 --- a/selftest/knownfail.d/python-segfaults +++ b/selftest/knownfail.d/python-segfaults @@ -1,6 +1,4 @@ -samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_auth_user_session 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_net_replicate_chunk_1 -samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_net_replicate_init__1 samba.tests.segfault.samba.tests.segfault.SegfaultTests.test_net_replicate_init__3