about summary refs log tree commit diff
path: root/malloc
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2010-04-03 09:47:01 -0700
committerUlrich Drepper <drepper@redhat.com>2010-04-03 09:47:01 -0700
commit90a3055e8bdd9308eceeadc0b37278f324ec6b5d (patch)
treebfc9f4126669415ab5e8b27b44d013433cbf2da2 /malloc
parent991eda1ec17665ea0da247f8eabc6993d020ed8e (diff)
downloadglibc-90a3055e8bdd9308eceeadc0b37278f324ec6b5d.tar.gz
glibc-90a3055e8bdd9308eceeadc0b37278f324ec6b5d.tar.xz
glibc-90a3055e8bdd9308eceeadc0b37278f324ec6b5d.zip
One more sanity check in free.
Diffstat (limited to 'malloc')
-rw-r--r--malloc/malloc.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 784919e4bd..558e8bab0a 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -4852,7 +4852,8 @@ _int_free(mstate av, mchunkptr p)
       free_perturb (chunk2mem(p), size - SIZE_SZ);
 
     set_fastchunks(av);
-    fb = &fastbin (av, fastbin_index(size));
+    unsigned int idx = fastbin_index(size);
+    fb = &fastbin (av, idx);
 
 #ifdef ATOMIC_FASTBINS
     mchunkptr fd;
@@ -4866,6 +4867,12 @@ _int_free(mstate av, mchunkptr p)
 	    errstr = "double free or corruption (fasttop)";
 	    goto errout;
 	  }
+	if (old != NULL
+	    && __builtin_expect (fastbin_index(chunksize(old)) != idx, 0))
+	  {
+	    errstr = "invalid fastbin entry (free)";
+	    goto errout;
+	  }
 	p->fd = fd = old;
       }
     while ((old = catomic_compare_and_exchange_val_rel (fb, p, fd)) != fd);
@@ -4877,6 +4884,12 @@ _int_free(mstate av, mchunkptr p)
 	errstr = "double free or corruption (fasttop)";
 	goto errout;
       }
+    if (*fb != NULL
+	&& __builtin_expect (fastbin_index(chunksize(*fb)) != idx, 0))
+      {
+	errstr = "invalid fastbin entry (free)";
+	goto errout;
+      }
 
     p->fd = *fb;
     *fb = p;