Browse Source

tdb2: check that records are of sufficient length in tdb_check.

Rusty Russell 15 years ago
parent
commit
b350cb6907
1 changed files with 8 additions and 0 deletions
  1. 8 0
      ccan/tdb2/check.c

+ 8 - 0
ccan/tdb2/check.c

@@ -372,6 +372,14 @@ int tdb_check(struct tdb_context *tdb,
 			if (tdb->methods->oob(tdb, off + len, false))
 			if (tdb->methods->oob(tdb, off + len, false))
 				goto fail;
 				goto fail;
 
 
+			if (len < sizeof(p->f)) {
+				tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
+					 "tdb_check: too short record %llu at"
+					 " %llu\n",
+					 (long long)len, (long long)off);
+				goto fail;
+			}
+
 			if (off + sizeof(p->u) == tdb->header.v.hash_off) {
 			if (off + sizeof(p->u) == tdb->header.v.hash_off) {
 				hash_found = true;
 				hash_found = true;
 			} else if (off + sizeof(p->u)
 			} else if (off + sizeof(p->u)