diff options
| author | Adrian Cochrane <adrianc@catalyst.net.nz> | 2015-11-18 15:25:20 +1300 |
|---|---|---|
| committer | Garming Sam <garming@samba.org> | 2015-12-04 06:08:29 +0100 |
| commit | 99b2fd4f5be9dca1ef66c8a8096e3e75fee84a7f (patch) | |
| tree | ad1975d0feae75dd15ee8eac90b4d19886985dd9 /lib/ldb/tests/python/api.py | |
| parent | c118fbc680f84622c12997cf347f3194d532ddbc (diff) | |
| download | samba-99b2fd4f5be9dca1ef66c8a8096e3e75fee84a7f.tar.gz samba-99b2fd4f5be9dca1ef66c8a8096e3e75fee84a7f.tar.bz2 samba-99b2fd4f5be9dca1ef66c8a8096e3e75fee84a7f.zip | |
ldb: Fix bug triggered by having an empty message in database during search.
Previously if the message had 0 elements, Talloc would reallocate the projected
array to NULL, fooling LDB into thinking that it failed to reallocate. This fix
corrects LDB to be able to handle the case where the message has no attributes
in common with the filter.
Also the realloc call resized the array to the number of elements in the message,
not the number of elements in common with the filter -- it essentially did nothing.
Unlike talloc_realloc, talloc_array always returns a non-null pointer. This would
help protect against possible errors.
Signed-off-by: Adrian Cochrane <adrianc@catalyst.net.nz>
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib/ldb/tests/python/api.py')
| -rwxr-xr-x | lib/ldb/tests/python/api.py | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py index cb65199e884..af1ff03ce61 100755 --- a/lib/ldb/tests/python/api.py +++ b/lib/ldb/tests/python/api.py @@ -256,6 +256,23 @@ class SimpleLdb(TestCase): finally: l.delete(ldb.Dn(l, "dc=bar")) + def test_empty_dn(self): + l = ldb.Ldb(filename()) + self.assertEqual(0, len(l.search())) + m = ldb.Message() + m.dn = ldb.Dn(l, "dc=empty") + l.add(m) + rm = l.search() + self.assertEqual(1, len(rm)) + self.assertEqual(set(["dn", "distinguishedName"]), set(rm[0].keys())) + + rm = l.search(m.dn) + self.assertEqual(1, len(rm)) + self.assertEqual(set(["dn", "distinguishedName"]), set(rm[0].keys())) + rm = l.search(m.dn, attrs=["blah"]) + self.assertEqual(1, len(rm)) + self.assertEqual(0, len(rm[0])) + def test_modify_delete(self): l = ldb.Ldb(filename()) m = ldb.Message() @@ -270,10 +287,12 @@ class SimpleLdb(TestCase): m["bla"] = ldb.MessageElement([], ldb.FLAG_MOD_DELETE, "bla") self.assertEqual(ldb.FLAG_MOD_DELETE, m["bla"].flags()) l.modify(m) - rm = l.search(m.dn)[0] + rm = l.search(m.dn) self.assertEqual(1, len(rm)) + self.assertEqual(set(["dn", "distinguishedName"]), set(rm[0].keys())) rm = l.search(m.dn, attrs=["bla"]) - self.assertEqual(0, len(rm)) + self.assertEqual(1, len(rm)) + self.assertEqual(0, len(rm[0])) finally: l.delete(ldb.Dn(l, "dc=modifydelete")) @@ -291,10 +310,12 @@ class SimpleLdb(TestCase): m["bla"] = ldb.MessageElement([], ldb.FLAG_MOD_DELETE, "bla") self.assertEqual(ldb.FLAG_MOD_DELETE, m["bla"].flags()) l.modify(m) - rm = l.search(m.dn)[0] + rm = l.search(m.dn) self.assertEqual(1, len(rm)) + self.assertEqual(set(["dn", "distinguishedName"]), set(rm[0].keys())) rm = l.search(m.dn, attrs=["bla"]) - self.assertEqual(0, len(rm)) + self.assertEqual(1, len(rm)) + self.assertEqual(0, len(rm[0])) finally: l.delete(ldb.Dn(l, "dc=modifydelete")) |
