r7641: Fix based on work from "Shlomi Yaakobovich" <Shlomi@exanet.com> to catch
authorJeremy Allison <jra@samba.org>
Thu, 16 Jun 2005 16:43:23 +0000 (16:43 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:18:16 +0000 (13:18 -0500)
loops in corrupted tdb files.
Jeremy.
(This used to be commit f9f3037d6855259edd56fd5a23d63dbb37f0a751)

source4/lib/tdb/common/tdb.c

index e9cbc12b91afb3b1d12fa561c30c786dce5729c6..44533aad2712f267f85c559b982b998cd9943346 100644 (file)
@@ -1295,12 +1295,6 @@ static int tdb_next_lock(TDB_CONTEXT *tdb, struct tdb_traverse_lock *tlock,
                        tdb_off current;
                        if (rec_read(tdb, tlock->off, rec) == -1)
                                goto fail;
-                       if (!TDB_DEAD(rec)) {
-                               /* Woohoo: we found one! */
-                               if (lock_record(tdb, tlock->off) != 0)
-                                       goto fail;
-                               return tlock->off;
-                       }
 
                        /* Detect infinite loops. From "Shlomi Yaakobovich" <Shlomi@exanet.com>. */
                        if (tlock->off == rec->next) {
@@ -1308,6 +1302,13 @@ static int tdb_next_lock(TDB_CONTEXT *tdb, struct tdb_traverse_lock *tlock,
                                goto fail;
                        }
 
+                       if (!TDB_DEAD(rec)) {
+                               /* Woohoo: we found one! */
+                               if (lock_record(tdb, tlock->off) != 0)
+                                       goto fail;
+                               return tlock->off;
+                       }
+
                        /* Try to clean dead ones from old traverses */
                        current = tlock->off;
                        tlock->off = rec->next;