tdb: Make tdb_dump_chain circular-list safe
authorVolker Lendecke <vl@samba.org>
Thu, 4 Oct 2018 13:00:15 +0000 (15:00 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 8 Oct 2018 20:17:10 +0000 (22:17 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/tdb/common/dump.c

index 73286b8735071f0062e9b50f34b9a343361e62fc..d4e3478469b18d43f3024b0f621674875405d0f5 100644 (file)
@@ -60,6 +60,7 @@ static tdb_off_t tdb_dump_record(struct tdb_context *tdb, int hash,
 
 static int tdb_dump_chain(struct tdb_context *tdb, int i)
 {
+       struct tdb_chainwalk_ctx chainwalk;
        tdb_off_t rec_ptr, top;
 
        if (i == -1) {
@@ -74,11 +75,19 @@ static int tdb_dump_chain(struct tdb_context *tdb, int i)
        if (tdb_ofs_read(tdb, top, &rec_ptr) == -1)
                return tdb_unlock(tdb, i, F_WRLCK);
 
+       tdb_chainwalk_init(&chainwalk, rec_ptr);
+
        if (rec_ptr)
                printf("hash=%d\n", i);
 
        while (rec_ptr) {
+               bool ok;
                rec_ptr = tdb_dump_record(tdb, i, rec_ptr);
+               ok = tdb_chainwalk_check(tdb, &chainwalk, rec_ptr);
+               if (!ok) {
+                       printf("circular hash chain %d\n", i);
+                       break;
+               }
        }
 
        return tdb_unlock(tdb, i, F_WRLCK);