diff options
author | Petr Viktorin <pviktori@redhat.com> | 2015-08-21 10:07:17 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2015-11-05 18:04:24 +0100 |
commit | a4d9c87cedeacbf3b4bbb5214a5b76e0def03540 (patch) | |
tree | 529c8a47f461a8402425cf58a360dd5be34b0a9f | |
parent | 2a29e36e4fc72e7ac460aafbbcf88e0106fb0cf6 (diff) | |
download | samba-a4d9c87cedeacbf3b4bbb5214a5b76e0def03540.tar.gz |
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>
-rw-r--r-- | lib/ldb/pyldb.c | 6 | ||||
-rwxr-xr-x | lib/ldb/tests/python/api.py | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index ba7186036f7..efb95f50343 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -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[] = { diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py index 2d9537fc2eb..a46c1ae1bff 100755 --- a/lib/ldb/tests/python/api.py +++ b/lib/ldb/tests/python/api.py @@ -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) |