1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

pyldb: Prevent segfault when first module is NULL

Signed-off-by: Petr Viktorin <pviktori@redhat.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
This commit is contained in:
Petr Viktorin 2015-08-21 10:07:17 +02:00 committed by Stefan Metzmacher
parent 2a29e36e4f
commit a4d9c87ced
2 changed files with 14 additions and 1 deletions

View File

@ -2045,7 +2045,11 @@ static PyObject *PyLdbModule_FromModule(struct ldb_module *mod)
static PyObject *py_ldb_get_firstmodule(PyLdbObject *self, void *closure)
{
return PyLdbModule_FromModule(pyldb_Ldb_AsLdbContext(self)->modules);
struct ldb_module *mod = pyldb_Ldb_AsLdbContext(self)->modules;
if (mod == NULL) {
Py_RETURN_NONE;
}
return PyLdbModule_FromModule(mod);
}
static PyGetSetDef py_ldb_getset[] = {

View File

@ -70,6 +70,15 @@ class SimpleLdb(TestCase):
x = ldb.Ldb(filename())
self.assertEqual("[<ldb module 'tdb'>]", repr(x.modules()))
def test_firstmodule_none(self):
x = ldb.Ldb()
self.assertEqual(x.firstmodule, None)
def test_firstmodule_tdb(self):
x = ldb.Ldb(filename())
mod = x.firstmodule
self.assertEqual(repr(mod), "<ldb module 'tdb'>")
def test_search(self):
l = ldb.Ldb(filename())
self.assertEqual(len(l.search()), 0)