Detect tight loop in tdb_find()
authorJim McDonough <jmcd@samba.org>
Thu, 21 May 2009 20:26:26 +0000 (16:26 -0400)
committerJim McDonough <jmcd@samba.org>
Thu, 21 May 2009 20:29:48 +0000 (16:29 -0400)
lib/tdb/common/tdb.c

index 8c61ec1a89d0e6303a507e24455940d9eeff13ab..b59bb1571c3af92f4f75a1f19e3448ed706694db 100644 (file)
@@ -96,6 +96,11 @@ static tdb_off_t tdb_find(struct tdb_context *tdb, TDB_DATA key, uint32_t hash,
                                      NULL) == 0) {
                        return rec_ptr;
                }
+               /* detect tight infinite loop */
+               if (rec_ptr == r->next) {
+                       TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_find: loop detected.\n"));
+                       return TDB_ERRCODE(TDB_ERR_CORRUPT, 0);
+               }
                rec_ptr = r->next;
        }
        return TDB_ERRCODE(TDB_ERR_NOEXIST, 0);