Browse Source

tdb2: fix use after free on error message

We use "r" after we call tdb_access_release() when we find corruption
in the free list.  "r" may be a pointer into malloced memory, freed
by tdb_access_release().
Rusty Russell 15 years ago
parent
commit
40bab4d5df
1 changed files with 1 additions and 1 deletions
  1. 1 1
      ccan/tdb2/free.c

+ 1 - 1
ccan/tdb2/free.c

@@ -457,12 +457,12 @@ again:
 		}
 
 		if (frec_magic(r) != TDB_FREE_MAGIC) {
-			tdb_access_release(tdb, r);
 			ecode = tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
 					   "lock_and_alloc:"
 					   " %llu non-free 0x%llx",
 					   (long long)off,
 					   (long long)r->magic_and_prev);
+			tdb_access_release(tdb, r);
 			goto unlock_err;
 		}