pytdb: Fix repr segfault for internal db
authorKirill Smelkov <kirr@mns.spb.ru>
Sun, 19 Sep 2010 09:53:21 +0000 (13:53 +0400)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 7 Oct 2010 04:41:14 +0000 (15:11 +1030)
The problem was tdb->name is NULL for TDB_INTERNAL databases, and
so it was crashing ...

    #0  0xb76944f3 in strlen () from /lib/i686/cmov/libc.so.6
    #1  0x0809862b in PyString_FromFormatV (format=0xb72b6a26 "Tdb('%s')", vargs=0xbfc26a94 "")
        at ../Objects/stringobject.c:211
    #2  0x08098888 in PyString_FromFormat (format=0xb72b6a26 "Tdb('%s')") at ../Objects/stringobject.c:358
    #3  0xb72b65f2 in tdb_object_repr (self=0xb759e060) at ./pytdb.c:439

Cc: 597089@bugs.debian.org
Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru>
Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
lib/tdb/pytdb.c
lib/tdb/python/tests/simple.py

index 58db1a8a6db4d2f978b2c614ee9b1da9da6edf34..d904e47e830ae7e1e05928bec03abb65a030225a 100644 (file)
@@ -409,7 +409,9 @@ static PyGetSetDef tdb_object_getsetters[] = {
 
 static PyObject *tdb_object_repr(PyTdbObject *self)
 {
-       return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx));
+       return PyString_FromFormat("Tdb('%s')",
+               (tdb_get_flags(self->ctx) & TDB_INTERNAL) ? "<internal>"
+                                                         : tdb_name(self->ctx));
 }
 
 static void tdb_object_dealloc(PyTdbObject *self)
index 0b8b8d922431f7cc65e5b4b5f6389a27bcf53594..2b72fff75d42874c7322a43be1baf1f560498245 100644 (file)
@@ -25,6 +25,14 @@ class CloseTdbTests(TestCase):
         self.tdb.close()
 
 
+class InternalTdbTests(TestCase):
+    def test_repr(self):
+        self.tdb = tdb.Tdb("whatever", tdb_flags=tdb.INTERNAL)
+
+        # repr used to crash on internal db
+        self.assertEquals(repr(self.tdb), "Tdb('<internal>')")
+
+
 class SimpleTdbTests(TestCase):
     def setUp(self):
         super(SimpleTdbTests, self).setUp()